Unable to instantiate activity Component Info Class Not found exception Android

二次信任 提交于 2019-12-12 05:27:36

问题


My app is deployed directly to any device without any exception. But when .apk is installed it throws the following exception. Secondly it runs fine with Nougat 7.0 and above versions but crashes with same exception for lower OS Versions like 5.0 and 6.0. etc. What is the reason for exception ?

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 {
}

and Stack trace is

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.access$800(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.access$800(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

and Folder Structure:


回答1:


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:

For Debug Build

  • Delete you build folder inside the App folder.
  • Goto Build>Build APk. it will generate .apk file in your app>build>output>apk directory.
  • COPY it your device and install manually.

For Release Build

  • Delete you build folder inside the App folder.
  • Goto Build>Generate Signed APk and provide recomended Details, make sure your Build type : release and have checked both signature version v1(jar signature) and v2(full apk signature) . it will generate .apk file in your app>build>output>apk directory.
  • COPY it your device and install manually.



回答2:


At first "Clean" and "Sync Project with Gradle Files". Then run your code




回答3:


Replace this

<activity
        android:name="amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"         
</activity>

with this

 <activity
        android:name=".amitechnologies.products.apps.equalizeraudioplayer.v3.view.LoaderOfAllMediaFiles"         
 </activity>

The reason is you have missed a dot(.) in android:name




回答4:


If your minSDK version less than 21 you need to do the following for 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>



回答5:


Delete your Build folder inside the app folder and rebuild your project



来源:https://stackoverflow.com/questions/44543270/unable-to-instantiate-activity-component-info-class-not-found-exception-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!