java - 获取失败的解决方案:Lcom/google/zxing/RGBLuminanceSource;实施 AAR 时
问题描述
我正在构建一个 AAR,在其中实现了 Zxing 库。当我尝试在另一个应用程序中使用此 AAR 时,它会给出
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/zxing/RGBLuminanceSource;
以下方法
public static String decodeQRImage(Bitmap bMap) {
String value = null;
int[] intArray = new int[bMap.getWidth() * bMap.getHeight()];
bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());
LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Reader reader = new QRCodeReader();
try {
Result result = reader.decode(bitmap);
value = result.getText();
} catch (NotFoundException e) {
e.printStackTrace();
value = e.getMessage();
} catch (ChecksumException e) {
e.printStackTrace();
value = e.getMessage();
} catch (FormatException e) {
value = e.getMessage();
e.printStackTrace();
}
return value;
}
当我直接在应用程序中使用上述方法而不在 AAR 中实现它时,它运行完美
以下是 AAR 中使用的依赖项
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test:runner:1.2.0'
implementation 'com.kaopiz:kprogresshud:1.2.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'com.github.f0ris.sweetalert:library:1.5.1'
implementation 'com.google.android.gms:play-services-vision:18.0.0'
implementation 'com.scottyab:rootbeer-lib:0.0.7'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation "androidx.versionedparcelable:versionedparcelable:1.1.0"
implementation 'com.google.android.play:core:1.6.3'
implementation 'org.jsoup:jsoup:1.11.3'
以下是应用程序中使用的依赖项
implementation project(":ziplibrary-debug")
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
解决方案
AAR 仅使用您的代码构建。默认情况下,AAR 中没有依赖项。这是有关如何将依赖项包含到 AAR中的选项。
此外,了解传递依赖关系可能会有所帮助:Transitive dependencies notsolved for aar library using gradle
更新
要解决META-INF
文件问题,您可以使用 Gradle packagingOptions
。在您的build.gradle
文件查找android
块内并插入以下内容:
android {
...
packagingOptions {
exclude 'META-INF/retrofit.kotlin_module'
}
}
推荐阅读
- javascript - 试图缓解 JavaScript 上的点击事件
- python - 如何使用 python 组合多个 .h5 文件(但形状相同)?
- vue.js - VueJS Bootstrap-Vue b-table - 复选框所有和当前项目?
- jmeter - 在 JMeter 中操作字符串变量
- jquery - 更改属性 Django 内联表单集的值
- firebase - 具有特定 uid 的 Firebase 函数 Typescript initializeAdmin()
- javascript - 更改水平滚动条的宽度。自定义滚动条?
- java - 给定 base 和 n 都为 1 或更大,递归(无循环)计算 base 的 n 次方的值,因此 powerN(3, 2) 为 9(3 的平方)。在java中
- mysql - 在插入时禁用 innodb_log_file 写入,AWS
- javascript - D3 奇怪地附加 tbody 每隔一个渲染