简体   繁体   English

自定义库上的java.lang.ClassNotFoundException

[英]java.lang.ClassNotFoundException on custom library

I created a library and this library use another external library (just one). 我创建了一个库,此库使用另一个外部库(仅一个)。

This is the configuration of my library: 这是我的库的配置:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    compile ('com.github.Paroca72:sc-gauges:3.0.1') {
        transitive=true
    }
}

Export the library, as .aar, using gradle -> :library -> assembleRelease. 使用gradle->:library-> assembleRelease将库导出为.aar。 Now iclude the library in a new project using "import .JAR/.AAR package" and including it in "module dependency".. 现在,使用“ import .JAR / .AAR包”将库包含在新项目中,并将其包含在“模块依赖项”中。

In the coding phase I no have errors but when I try to start the application I have this kind of exception: 在编码阶段,我没有错误,但是当我尝试启动应用程序时,我遇到了这种异常:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sccomponents.codes.gauges.ScArcGauge" on path: DexPathList[[zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/base.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_dependencies_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_0_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_1_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_2_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_3_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_4_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_5_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_6_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_7_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_8_apk.apk", zip file "/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.test.test-oKxgn-etFOgh1n6SqKQU5Q==/lib/x86, /system/lib, /vendor/lib]]

Referred to the external library "com.sccomponents.codes.gauges.ScArcGauge" that was include in my own library.. 引用包含在我自己的库中的外部库“ com.sccomponents.codes.gauges.ScArcGauge”。

What wrong? 怎么了

I'm using Android Studio (latest version) 我正在使用Android Studio(最新版本)

Most likely when you included your library via Android Studio you ended up with something like 最有可能的是,当您通过Android Studio包含库时,最终会遇到类似

compile 'yourlibrary":1.0.0@aar'

So it means that only the aar will be pulled in and not your dependencies. 因此,这意味着只有aar会被拉入而不是您的依赖项。 You need to change it to 您需要将其更改为

compile ('yourlibrary":1.0.0@aar'){ transitive=true }

Please follow the below steps. 请按照以下步骤操作。

  1. Right click on your project and select Properties. 右键单击您的项目,然后选择“属性”。
  2. Select Java Build Path from the menu on the left. 从左侧菜单中选择Java Build Path。
  3. Select the Order and Export tab. 选择订单和导出标签。
  4. From the list make sure the libraries or external jars you added to your project are checked. 从列表中,确保选中了添加到项目中的库或外部jar。
  5. Finally, clean your project & run. 最后,清理您的项目并运行。

May be because its not added the library at run time. 可能是因为它没有在运行时添加库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM