我有一些库文件。将根gradle类路径2.1.0更改为2.2.1后,出现NoClassDefFoundError错误。
例如:在同步后,我的aar库中创建了一个新类,我的主应用程序看到了我的类,但是当我运行应用程序时,在运行时它给了我NoClassDefFoundError。
附言:更新后,gradle下载了2.14.1。
threadid=1: thread exiting with uncaught exception (group=0xa4ca8b20)
: java.lang.NoClassDefFoundError: com.gk.lib.ui.Utils
: at com.example.activities.MainActivity.onCreate(MainActivity.java:78)
: at android.app.Activity.performCreate(Activity.java:5231)
: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
: at android.app.ActivityThread.access$800(ActivityThread.java:135)
: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
: at android.os.Handler.dispatchMessage(Handler.java:102)
: at android.os.Looper.loop(Looper.java:136)
: at android.app.ActivityThread.main(ActivityThread.java:5001)
: at java.lang.reflect.Method.invokeNative(Native Method)
: at java.lang.reflect.Method.invoke(Method.java:515)
: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
: at dalvik.system.NativeStart.main(Native Method)
在我的MainActivity类中,我使用如下静态方法调用方法:
Utils.gkTestMethod();
我的实用程序类:
import android.util.Log;
public class Utils {
public static void gkTestMethod(){
Log.v("Log","Log");
}
}
我叫什么课都没关系。如果我创建新类,它将给出此错误。
谢谢。
最佳答案
关于此片段的主要build.gradle
中:
dependencies { compile('com.gk.lib:common:1.0.0') { transitive = true } compile('com.gk.lib:ui:1.0.0') { transitive = true exclude module: 'common' } compile('com.gk.lib:components:1.0.0') { transitive = true exclude module: 'common' exclude module: 'ui' } // Other dependencies }
看来
components
取决于common
和ui
,而ui
取决于common
。是否有充分的理由明确排除然后重新包括传递依赖项?我认为这应该工作:dependencies {
compile 'com.gk.lib:components:1.0.0'
// Other dependencies
}
而且IIRC的
common
不能传递。
关于android - 将Gradle 2.1.0更新为2.2.1后出现NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40219507/