java Android 应用程序启动后立即关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36042956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android app closes immediately after launching
提问by wblaschko
I'm trying to finish off my app for publishing on the google play store so uploaded to the alpha testing phase. When trying to launch the app it closes immediately and this is the error that I receive:
我正在尝试完成我的应用程序,以便在 google Play 商店上发布,因此上传到 alpha 测试阶段。尝试启动应用程序时,它会立即关闭,这是我收到的错误:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.FinalFrontier.MoonLanding/com.FinalFrontier.MoonLanding.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.FinalFrontier.MoonLanding.MainActivity" on path: DexPathList[[zip file "/data/app/com.FinalFrontier.MoonLanding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.FinalFrontier.MoonLanding-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2192)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access0(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.FinalFrontier.MoonLanding.MainActivity" on path: DexPathList[[zip file "/data/app/com.FinalFrontier.MoonLanding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.FinalFrontier.MoonLanding-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2183)
... 11 more
? This is my first ever app and I'm pretty new to this so any help would be greatly appreciated. I've read the documentation and searched the errors online however can't seem to get any of the solutions to work. Here's a copy of my android manifest.
? 这是我的第一个应用程序,我对此很陌生,因此将不胜感激。我已阅读文档并在线搜索错误,但似乎无法获得任何解决方案。这是我的 android 清单的副本。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.1" package="com.FinalFrontier.MoonLanding" android:installLocation="preferExternal">
<application android:icon="@drawable/app_icon" android:label="@String/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">
<activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@String/app_name" android:name="com.FinalFrontier.MoonLanding.CustomActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:hardwareAccelerated="true" android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedAttribute" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
Anybody got any ideas? Thanks in advance.
有人有任何想法吗?提前致谢。
回答by wblaschko
Essentially what is happening is your application is unable to find the class it's looking for in the compiled APK and is crashing.
基本上发生的事情是您的应用程序无法在已编译的 APK 中找到它正在寻找的类并且正在崩溃。
This can happen for several reasons.
这可能有多种原因。
Try this first
先试试这个
The most common I've found is that the IDE has messed up its build cache somewhere. In this case: restart Android Studio, clear the cache, and rebuild the project.
我发现的最常见的是 IDE 在某处弄乱了它的构建缓存。这种情况:重启Android Studio,清除缓存,重建工程。
Try this second
试试这一秒
It's also possible that you have enough methods that you're pushing the Android method limit (see this), in which case you'll have to enable multidexin your application or use Proguard to minimize your app (this is more complicated, but start here).
也有可能您有足够的方法来推动 Android 方法限制(请参阅此),在这种情况下,您必须在您的应用程序中启用 multidex或使用 Proguard 来最小化您的应用程序(这更复杂,但开始在这里)。