无法构建 APK (Android Studio)

Can't not build the APK (Android Studio)

我 运行 我 phone 上的项目和安装应用程序很好(在 Android Studio 中),
但是当我想使用项目文件中的 apk 安装应用程序时,应用程序崩溃了。 这是错误信息

04-27 20:33:38.607 2206-2206/? E/AndroidRuntime: FATAL EXCEPTION: main
             Process: example.myapplication, PID: 2206
             java.lang.RuntimeException: Unable to instantiate application example.myapplication.AppController: java.lang.ClassNotFoundException: Didn't find class "example.application.AppController" on path: DexPathList[[zip file "/data/app/example.myapplication-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
             at android.app.LoadedApk.makeApplication(LoadedApk.java:563)
             at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4491)
             at android.app.ActivityThread.access00(ActivityThread.java:144)
             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
             at android.os.Handler.dispatchMessage(Handler.java:102)
             at android.os.Looper.loop(Looper.java:135)
             at android.app.ActivityThread.main(ActivityThread.java:5221)
             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:899)
             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
             Caused by: java.lang.ClassNotFoundException: Didn't find class "example.myapplication.AppController" on path: DexPathList[[zip file "/data/app/example.myapplication-2/base.apk"],nativeLibraryDirectories=[/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.newApplication(Instrumentation.java:979)
             at android.app.LoadedApk.makeApplication(LoadedApk.java:558)
             at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4491) 
             at android.app.ActivityThread.access00(ActivityThread.java:144) 
             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) 
             at android.os.Handler.dispatchMessage(Handler.java:102) 
             at android.os.Looper.loop(Looper.java:135) 
             at android.app.ActivityThread.main(ActivityThread.java:5221) 
             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:899) 
             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
             Suppressed: java.lang.ClassNotFoundException: example.myapplication.AppController
             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

当我构建 APK 时也出现错误。

> Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl.class

感谢解答!

--build.gradle--

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "example.myapplication"
        minSdkVersion 20
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    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 project(path: ':weekViewLibrary')
    compile project(path: ':dateAndTimePicker')
    compile project(path: ':tablelistlibrary')
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.afollestad.material-dialogs:commons:0.9.4.2'
    compile 'com.github.ganfra:material-spinner:1.1.1'
    compile 'com.nispok:snackbar:2.11.0'
    compile 'de.codecrafters.tableview:tableview:2.5.0'
    compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
    compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.0.2'

    testCompile 'junit:junit:4.12'
}

检查清单中的 activity 包名称和 运行

如果不起作用,请从项目文件夹中删除构建文件夹并重建项目

尝试将如下所示的排除模块添加到依赖项部分的 build.gradle 文件中。

dependencies {
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
        exclude module: 'support-annotations'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
        exclude module: 'design'
    }
}

'org.eclipse.paho:org.eclipse.paho.android.service:1.0.2' 包括支持-v4

更改代码

    compile ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
         exclude module: 'support-v4'
    }

并解决!