问题
I have found a lot of similar questions, but no one helps me.
I have next problem. I have complete project for Android and I have to export it's functionality to .aar
library. First of all I created new project and created new module where put my source project. At this step all things goes well and I get my mylib.aar
file in /build/outputs/aar/
folder. Then I created new project to test my mylib.aar
, so I created libs
folder under my app
folder in Android Studio, and in build.gradle
file of my test project I added these lines:
repositories {
flatDir {dirs 'libs'}
}
dependencies {
compile(name: 'mylib', ext: 'aar')
}
In manifest file I added declaration of MainActivity from library:
<activity android:name="com.testlib.mylib.MainActivity"
android:label="MainActivity"/>
Android Studio found this file well and I even can watch source code through built-in decompiler. But when I try to start this activity from another activity that isn't placed in my lib I get this error:
3838-3838/com.testapp.testsdkapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.testapp.testsdkapp, PID: 3838
java.lang.NoClassDefFoundError: com.testlib.mylib.MainActivity$RegisterInBackgroundTask
at com.testlib.mylib.MainActivity.registerInBackground(MainActivity.java:1551)
at com.testlib.mylib.MainActivity.onCreate(MainActivity.java:269)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
RegisterInBackgroundTask
is inner public AsyncTask
class declared in my MainActivity in the library. I tried to put mylib.aar
in aar
folder and declare in build.gradle
in other way, but it didn't help me and I get similar error.
If this information is not enough, I'll add required parts of code etc. So please help me, if you know how to solve my problem! Thanks.
回答1:
import mylib.aar as module in your project and inside dependencies add following line
compile project(':mylib')
来源:https://stackoverflow.com/questions/29941807/java-lang-noclassdeffounderror-at-runtime-in-activitys-inner-class