无法实例化活动ComponentInfo Android Studio 2.3.2

时间:2017-05-22 06:31:44

标签: android android-studio android-gradle

enter image description here enter image description here`

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

`我创建了一个示例项目,并通过谷歌驱动器共享调试.apk文件,并尝试安装它崩溃。我可以毫无问题地从USB安装应用程序。我正在追随。我发布了我的gradle文件。不知道发生了什么

05-22 11:54:57.363 22469-22469/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: chin.demo.app.com.nm, PID: 22469
                                               java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{chin.demo.app.com.nm/chin.demo.app.com.nm.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "chin.demo.app.com.nm.MainActivity" on path: DexPathList[[zip file "/data/app/chin.demo.app.com.nm-1/base.apk"],nativeLibraryDirectories=[/data/app/chin.demo.app.com.nm-1/lib/arm, /vendor/lib, /system/lib]]
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:148)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                Caused by: java.lang.ClassNotFoundException: Didn't find class "chin.demo.app.com.nm.MainActivity" on path: DexPathList[[zip file "/data/app/chin.demo.app.com.nm-1/base.apk"],nativeLibraryDirectories=[/data/app/chin.demo.app.com.nm-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:1067)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:148) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                Suppressed: java.lang.ClassNotFoundException: chin.demo.app.com.nm.MainActivity
                                                   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)
                                                        ... 12 more
                                                Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available




apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "chin.demo.app.com.nm"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

`

2 个答案:

答案 0 :(得分:0)

使用 AndroidStudio

生成apk文件
  

BUILD - &gt;建立APK

// Enabling multidex support.
    multiDexEnabled true

  1. 右键单击您的项目,然后选择属性
  2. 从左侧菜单中选择 Java Build Path
  3. 选择订单和导出标签。
  4. 从列表中确保您添加到项目中的库或外部jar已已选中
  5. 最后,清理您的项目&amp;运行。
  6. 希望它有效。

答案 1 :(得分:0)

在您的CMD /终端中尝试使用此命令来构建apk: gradlew assembleDebug