我 这种包格式:
com
example
name
oldAppName
现在,我将Shift + F6重构并重命名为这个:
com
myCompanyName
name
newAppName
然而,现在当我运行我的应用程序时,我遇到了这个崩溃:
java.lang.ClassNotFoundException: Didn't find class "com.example.name.oldAppName.Application" on path: DexPathList[[zip file "/data/app/com.myCompanyName.name.newAppName1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
我的Application.java
位于newAppName
之下,并且它在Manifest中正确定义
我尝试过的是:
applicationId
事实上,这是我的应用程序清单标记:
<application
android:name=".Application"
...
>
甚至将.Application
更改为完整的包名称(com.blah.blah.Application
) DIDN&#39; T WORK。
我错过了什么吗?有缺失的一步吗?
以下是完整日志:
java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.name.oldAppName.Application
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4345)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.name.oldAppName.Application
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:220)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
at android.app.Application.attach(Application.java:181)
at android.app.Instrumentation.newApplication(Instrumentation.java:1008)
at android.app.Instrumentation.newApplication(Instrumentation.java:992)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4345)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.example.name.oldAppName.Application
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
at android.app.Application.attach(Application.java:181)
at android.app.Instrumentation.newApplication(Instrumentation.java:1008)
at android.app.Instrumentation.newApplication(Instrumentation.java:992)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4345)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.example.name.oldAppName/Application
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
at android.app.Application.attach(Application.java:181)
at android.app.Instrumentation.newApplication(Instrumentation.java:1008)
at android.app.Instrumentation.newApplication(Instrumentation.java:992)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4345)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.name.oldAppName.Application" on path: DexPathList[[zip file "/data/app/com.newCompanyName.name.newAppName-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.myCompanyName.name.newAppName-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209)
at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
at android.app.Application.attach(Application.java:181)
at android.app.Instrumentation.newApplication(Instrumentation.java:1008)
at android.app.Instrumentation.newApplication(Instrumentation.java:992)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4345)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:5)
有时,停用即时运行会解决问题。
或者,如果禁用“即时运行”无效,问题可能在于Android Studio尚未识别更改。 首先备份您的项目并注意您必须在此之后重新配置您的VCS(但不会丢失任何提交或分支,只需注册您的VCS。)
删除应用的.idea和[yourProjectName] .iml。
完成重命名包后,将gradle中的applicationId
替换为正确的
同步草图
清理并重建
您可以找到更好的版本,了解如何正确重构您的包here
P.S:您必须在未获得“ClassNotFound”异常的位置恢复原始包名称并尝试上述解决方案。
答案 1 :(得分:3)
对于那些来到这里的人,至少在Android Gradle插件版本2.2.3中,有一个错误主动缓存即时运行用来检索应用程序ID和应用程序类的工件。您可以通过执行rm -rf ~/.android/build-cache
然后执行干净重建然后启动应用来解决问题。
有一种方法可以通过执行find ~/.android/build-cache -type f | xargs grep -l AppInfo
并仅删除匹配的缓存文件夹来限制删除:
$ find ~/.android/build-cache -type f | xargs grep -l AppInfo
/Users/joe/.android/build-cache/dde3e201178401491cae141d479a0b4113bf3a0e/output/classes.dex
/Users/joe/.android/build-cache/f7d636c8af71d68edfb468297d20157f3eb6659c/output/classes.dex
$ rm -rf /Users/joe/.android/build-cache/dde3e201178401491cae141d479a0b4113bf3a0e
$ rm -rf /Users/joe/.android/build-cache/f7d636c8af71d68edfb468297d20157f3eb6659c
这将解决问题,直到下一个应用程序ID /包重命名。
请参阅此处的详细信息code.google.com/p/android/issues/detail?id=229128#c8
答案 2 :(得分:0)
我在重构了一个java类后遇到了类似的问题,我通过清理项目结构解决了这个问题。
在此之后,一切都得到了解决。
答案 3 :(得分:0)
在进行干净构建之前,请检查以下内容,以确保使用新的类名更新了以下所有内容。
此后,您进行干净的构建/重建。
答案 4 :(得分:0)
对于那些在尝试重命名基于Qt的Android应用程序时看到完全相同的错误消息之后来到这里的人:要重命名它,只需在您的AndroidManifest.xml
中适应以下XML属性:
<!-- application package name as seen in Google Play URLs,
in the output of `adb shell pm list packages` etc. -->
<manifest package="com.example.appname" …>
<!-- application name as shown below the app icon -->
<application … android:label="App Name" …>
<!-- application name "sometimes" shown below the app icon -->
<activity … android:label="appname" …>
请勿触摸以下属性,因为这会导致此处所述的症状:
<application … android:name="org.qtproject.qt5.android.bindings.QtApplication" …>
<activity … android:name="org.qtproject.qt5.android.bindings.QtActivity" …>
原因是,在Android的Qt应用程序中,您没有定义要在main.cpp
中启动的Android活动。相反,程序anroiddeployqt
生成引导Java代码,该代码最终从main.cpp
调用您的C ++代码。该引导代码需要如上所述的应用程序和活动名称。但是您可以更改其标签(显示名称)–参见上文。