【问题标题】:Getting Failed resolution of: Lcom/google/zxing/RGBLuminanceSource; when implementing AAR获取失败的解决方案:Lcom/google/zxing/RGBLuminanceSource;实施 AAR 时
【发布时间】: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 依赖项?如果是,那么我将不得不在应用程序中添加所有其他依赖项

标签: java android zxing aar


【解决方案1】:

AAR 仅使用您的代码构建。默认情况下,AAR 中没有依赖项。这是how to include dependencies into AAR 上的一个选项。

另外,了解传递依赖可能会有所帮助:Transitive dependencies not resolved for aar library using gradle

更新

要解决 META-INF 文件的问题,您可以使用 Gradle packagingOptions。在您的 build.gradle 文件中找到 android 块并插入以下内容:

android {
    ...

    packagingOptions {
        exclude 'META-INF/retrofit.kotlin_module'
    }
}

【讨论】:

  • 谢谢,我使用任务添加了所有依赖项并且它有效。但是,如果有人使用我的 AAR 并在他的应用程序中添加与我在 AAR 中添加的相同的依赖项,则构建失败并显示此消息-More than one file was found with OS independent path 'META-INF/retrofit.kotlin_module'
猜你喜欢
  • 2015-04-01
  • 2020-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-09
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
相关资源
最近更新 更多