将 Android studio 项目从 Windows 移动到 Mac 后出现 ClassNotFoundException (AppCompatActivity.class)

ClassNotFoundException (AppCompatActivity.class) after moving Android studio project from Windows to Mac

:)

我目前正在使用 Android Studio 开发一个 Android 应用程序,在我的 Windows 机器上开发它一段时间后,我目前正在尝试获取它 运行 在我的 MacBook Air 上。

我复制了项目文件并在 Mac (API 25) 上创建了一个模拟器。该项目编译得很好,但由于以下错误,它立即在模拟器上崩溃:

FATAL EXCEPTION: main
                                                                       Process: com.lennartschoch.partytime, PID: 5736
                                                                       java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.lennartschoch.partytime/com.lennartschoch.partytime.LoadingActivity}: java.lang.ClassNotFoundException: Didn't find class "com.lennartschoch.partytime.LoadingActivity" on path: DexPathList[[zip file "/data/app/com.lennartschoch.partytime-2/base.apk", zip file "/data/app/com.lennartschoch.partytime-2/split_lib_slice_3_apk.apk"],nativeLibraryDirectories=[/data/app/com.lennartschoch.partytime-2/lib/x86, /system/lib, /vendor/lib]]
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                        Caused by: java.lang.ClassNotFoundException: Didn't find class "com.lennartschoch.partytime.LoadingActivity" on path: DexPathList[[zip file "/data/app/com.lennartschoch.partytime-2/base.apk", zip file "/data/app/com.lennartschoch.partytime-2/split_lib_slice_3_apk.apk"],nativeLibraryDirectories=[/data/app/com.lennartschoch.partytime-2/lib/x86, /system/lib, /vendor/lib]]
                                                                           at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                           at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:154) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
                                                                        Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
                                                                           at java.lang.VMClassLoader.findLoadedClass(Native Method)
                                                                           at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
                                                                                ... 12 more
                                                                        Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatActivity" on path: DexPathList[[zip file "/data/app/com.lennartschoch.partytime-2/base.apk", zip file "/data/app/com.lennartschoch.partytime-2/split_lib_slice_3_apk.apk"],nativeLibraryDirectories=[/data/app/com.lennartschoch.partytime-2/lib/x86, /system/lib, /vendor/lib]]
                                                                           at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                ... 15 more

我已经(希望)当前实现了 Android 支持库 (v7),您可以在我的 build.gradle:

中看到它
apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.lennartschoch.partytime"
        minSdkVersion 19
        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(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
}

我已经尝试过清理和重建项目,但我就是无法解决这个问题。有什么建议吗?

谢谢!

dependencies {   

 compile fileTree(include: ['*.jar'], dir: 'libs')

       compile 'com.android.support:appcompat-v7:25.0.1'
        compile 'com.android.support:recyclerview-v7:25.0.1'
        compile 'com.android.support:cardview-v7:25.0.1'
        compile 'com.android.support:design:25.0.1'

       }

使用这些依赖项。

将 Android 项目移动到旧目录的子目录后,我遇到了同样的问题。首先,当我尝试 运行 在与之前相同的设备上的项目时,出现以下错误:

DELETE_FAILED_INTERNAL_ERROR
Error while Installing APKs

我通过 Build -> Clean Project 摆脱了这个问题,但后来我遇到了这些 ClassNotFound 异常,应用程序立即崩溃了。这是通过在项目根目录中的终端中 运行ning gradlew clean 并再次构建来解决的。