无法实例化 activity 组件信息 Class 未找到异常 Android
Unable to instantiate activity Component Info Class Not found exception Android
我的应用程序无一例外地直接部署到任何设备。但是安装 .apk 时会抛出以下异常。其次,它在 Nougat 7.0 及更高版本上运行良好,但在较低的 OS 版本(如 5.0 和 6.0)中崩溃并出现相同的异常。 etc. 异常的原因是什么?
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="amitechnologies.products.apps.equalizeraudioplayer.v3" >
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="amitechnologies.products.apps.equalizeraudioplayer.v3.view.MainActivity"
android:screenOrientation="sensorPortrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Build.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'm-zaes'
keyPassword 'm-zaes'
storeFile file('D:/AMI_Repo/AMI_Designer/Targets/Android/AMI 3d Player v3/keystore.jks')
storePassword 'm-zaes'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "amitechnologies.products.apps.equalizeraudioplayer.v3"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.1"
signingConfig signingConfigs.config
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFile 'D:/AMI_Repo/AMI_Designer/Targets/Android/AMI 3d Player v3/app/proguard-android.txt'
signingConfig signingConfigs.config
}
}
sourceSets {
main {
jniLibs.srcDir 'jniLibs'
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.android.gms:play-services-ads:10.2.4'
compile 'com.google.apis:google-api-services-youtube:v3-rev180-1.22.0'
compile 'com.android.support:multidex:1.0.1'
//glide
compile 'com.github.bumptech.glide:glide:3.7.0'
// CardView
compile 'com.android.support:cardview-v7:25.3.1'
}
productFlavors {
}
}
dependencies {
}
和堆栈跟踪是
Process: amitechnologies.products.apps.equalizeraudioplayer.v3, PID: 15548
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{amitechnologies.products.apps.equalizeraudioplayer.v3/amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles}: java.lang.ClassNotFoundException: Didn't find class "amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles" on path: DexPathList[[zip file "/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/base.apk"],nativeLibraryDirectories=[/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564)
at android.app.ActivityThread.access0(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5576)
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:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
Caused by: java.lang.ClassNotFoundException: Didn't find class "amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles" on path: DexPathList[[zip file "/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/base.apk"],nativeLibraryDirectories=[/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1070)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2385)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564)
at android.app.ActivityThread.access0(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5576)
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:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
Suppressed: java.lang.ClassNotFoundException: amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
和文件夹结构:
如果您的 minSDK 版本低于 21,您需要为 multidex 执行以下操作
build.gradle
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your_app_package">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
起初"Clean"和"Sync Project with Gradle Files"。然后运行你的代码
As Discussion in chat i found that, Your manual way of generating APK
is not generating the correct APK, so i am Suggesting these way to
generating APK for Manual Install:
用于调试构建
- 删除 App 文件夹中的 build 文件夹。
- 转到
Build>Build APk
。它会在你的
app>build>output>apk
目录。
- 将其复制到您的设备并手动安装。
发布版本
- 删除 App 文件夹中的 build 文件夹。
- 转到
Build>Generate Signed APk
并提供推荐的详细信息,确保您的 Build type : release
并检查了签名版本 v1(jar signature)
和 v2(full apk signature)
。它会在你的
app>build>output>apk
目录。
- 将其复制到您的设备并手动安装。
替换此
<activity
android:name="amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"
</activity>
有了这个
<activity
android:name=".amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"
</activity>
原因是您在 android:name
中遗漏了一个点 (.)
删除 app 文件夹中的 Build 文件夹并重建项目
我的应用程序无一例外地直接部署到任何设备。但是安装 .apk 时会抛出以下异常。其次,它在 Nougat 7.0 及更高版本上运行良好,但在较低的 OS 版本(如 5.0 和 6.0)中崩溃并出现相同的异常。 etc. 异常的原因是什么?
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="amitechnologies.products.apps.equalizeraudioplayer.v3" >
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="amitechnologies.products.apps.equalizeraudioplayer.v3.view.MainActivity"
android:screenOrientation="sensorPortrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Build.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'm-zaes'
keyPassword 'm-zaes'
storeFile file('D:/AMI_Repo/AMI_Designer/Targets/Android/AMI 3d Player v3/keystore.jks')
storePassword 'm-zaes'
}
}
compileSdkVersion 25
buildToolsVersion "25.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "amitechnologies.products.apps.equalizeraudioplayer.v3"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.1"
signingConfig signingConfigs.config
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFile 'D:/AMI_Repo/AMI_Designer/Targets/Android/AMI 3d Player v3/app/proguard-android.txt'
signingConfig signingConfigs.config
}
}
sourceSets {
main {
jniLibs.srcDir 'jniLibs'
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.android.gms:play-services-ads:10.2.4'
compile 'com.google.apis:google-api-services-youtube:v3-rev180-1.22.0'
compile 'com.android.support:multidex:1.0.1'
//glide
compile 'com.github.bumptech.glide:glide:3.7.0'
// CardView
compile 'com.android.support:cardview-v7:25.3.1'
}
productFlavors {
}
}
dependencies {
}
和堆栈跟踪是
Process: amitechnologies.products.apps.equalizeraudioplayer.v3, PID: 15548
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{amitechnologies.products.apps.equalizeraudioplayer.v3/amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles}: java.lang.ClassNotFoundException: Didn't find class "amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles" on path: DexPathList[[zip file "/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/base.apk"],nativeLibraryDirectories=[/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564)
at android.app.ActivityThread.access0(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5576)
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:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
Caused by: java.lang.ClassNotFoundException: Didn't find class "amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles" on path: DexPathList[[zip file "/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/base.apk"],nativeLibraryDirectories=[/data/app/amitechnologies.products.apps.equalizeraudioplayer.v3-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1070)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2385)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564)
at android.app.ActivityThread.access0(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5576)
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:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
Suppressed: java.lang.ClassNotFoundException: amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
和文件夹结构:
如果您的 minSDK 版本低于 21,您需要为 multidex 执行以下操作
build.gradle
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your_app_package">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
起初"Clean"和"Sync Project with Gradle Files"。然后运行你的代码
As Discussion in chat i found that, Your manual way of generating APK is not generating the correct APK, so i am Suggesting these way to generating APK for Manual Install:
用于调试构建
- 删除 App 文件夹中的 build 文件夹。
- 转到
Build>Build APk
。它会在你的app>build>output>apk
目录。 - 将其复制到您的设备并手动安装。
发布版本
- 删除 App 文件夹中的 build 文件夹。
- 转到
Build>Generate Signed APk
并提供推荐的详细信息,确保您的Build type : release
并检查了签名版本v1(jar signature)
和v2(full apk signature)
。它会在你的app>build>output>apk
目录。 - 将其复制到您的设备并手动安装。
替换此
<activity
android:name="amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"
</activity>
有了这个
<activity
android:name=".amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"
</activity>
原因是您在 android:name
中遗漏了一个点 (.)删除 app 文件夹中的 Build 文件夹并重建项目