【发布时间】:2020-07-10 08:19:11
【问题描述】:
我正在构建一个 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 中使用了 Zxing 依赖项,但在应用程序中没有。是否必须在应用程序中添加 Zxing 依赖项?如果是,那么我将不得不在应用程序中添加所有其他依赖项