问题描述
我发现了很多类似的问题,但没有人帮助我。
I have found a lot of similar questions, but no one helps me.
我有下一个问题。我有Android的完整的项目,我需要导出它的功能,以 .aar
库。首先,我创建新项目,并创造了新的模块,在这里把我的代码项目。在此步骤中所有的事情进展顺利,我得到我的 mylib.aar
文件中的 /生成/输出/ AAR /
文件夹。然后,我创建了新的项目来测试下我的 mylib.aar ,所以我创建库
文件夹> Android Studio中的应用程序文件夹,并在的build.gradle
我的测试项目中的文件我添加这些行:
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')
}
在manifest文件中,我从图书馆加到MainActivity声明:
In manifest file I added declaration of MainActivity from library:
<activity android:name="com.testlib.mylib.MainActivity"
android:label="MainActivity"/>
Android的工作室找到这个文件很好,我甚至可以通过内置的反编译观看源$ C $ C。但是,当我试图从没有摆在我的lib我得到这个错误的另一个活动启动本次活动:
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
的内部公开的AsyncTask
类,我在图书馆MainActivity声明。我试图把 mylib.aar
在 AAR
文件夹和的build.gradle 申报code>在其他的方式,但它并没有帮助我,我得到类似的错误。
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.
如果此信息是不够的,我会添加所需的零部件code等,所以请帮助我,如果你知道如何解决我的问题!谢谢你。
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.
推荐答案
进口mylib.aar作为您的项目和内部依赖模块添加以下行
import mylib.aar as module in your project and inside dependencies add following line
compile project(':mylib')
这篇关于java.lang.NoClassDefFoundError的在运行时活动的内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!