在其他计算机上打开项目(然后在第一台计算机上重新打开)后出现多个错误

时间:2018-11-13 12:57:52

标签: android

昨天我在另一台计算机上打开了Android项目(文件在我的OneDrive中,因此我从不“移动”文件),以便将该项目显示给某人。

现在,我在实际计算机上重新打开了该项目,并且生成了很多错误(请参见图片)。该项目以前运行良好。

它们都是Windows计算机。 我尝试重新同步gradle并重建项目,但是问题仍然存在。我做错了什么,更重要的是:如何解决(我对Android很陌生)。

奇怪的是,我仍然可以运行该应用程序而不会出错。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您缺少依赖项。

从外观上看,您缺少Android支持的依赖项,并且 凌空

确认您的build.gradle具有适当的库引用和存储库以将其提取,并且新计算机也已安装了sdk。

如果您使用的是28之前的版本,我希望在您的父项目gradle中看到。

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71' //if using kotlin
        classpath 'com.google.gms:google-services:4.1.0' //if using google services
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {url 'https://maven.google.com/'} //older android studio
        maven { url "https://jitpack.io" } //post api 28 needed
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

然后,在您的应用程序级别build.gradle中,如果您使用的是API 28,则应该具有依赖项来获取截击和支持库,如以下示例所示: 注意*如果您是28岁之前的用户,则将名称空间更新为非Androix路径。

dependencies {
   implementation 'com.google.firebase:firebase-crash:16.2.1' //crash reporting

   //to compile @synchronized things and java references
   implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.0"

   //Android ui support
   implementation 'com.google.android.material:material:1.0.0'
   implementation 'androidx.appcompat:appcompat:1.0.2'
   implementation 'androidx.legacy:legacy-support-v4:1.0.0'
   implementation 'androidx.cardview:cardview:1.0.0'
   implementation 'androidx.recyclerview:recyclerview:1.0.0'
   implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
   //Networking
   implementation 'com.android.volley:volley:1.1.1'

   // [START firebase]
   implementation 'com.google.firebase:firebase-core:16.0.5'
   implementation 'com.google.firebase:firebase-messaging:17.3.4'
   implementation 'com.google.firebase:firebase-appindexing:16.0.2'
   implementation 'com.google.android.gms:play-services-base:15.0.2'
   // [END   firebase]

   implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6'
}

然后,每当在新计算机上打开时,只需检查一下SDK路径是否正确即可。例如,永远不要将local.properties检入到存储库中,因为它具有用于“ local”属性的硬编码路径。

enter image description here

接下来,请确保菜单中的SDK路径正确,它是带有3个蓝色小方块的文件夹:

enter image description here

如果所有这些都很好,那么请执行build.clean并重新构建以查看是否可以清除问题。如果仍有问题,可以尝试

文件->使缓存无效并重置

最后,如果仍然不能解决问题,则可能是构建缓存问题,因此删除所有iml文件,idea文件,构建文件夹,然后仅从代码中导入项目。我猜您正在将项目的物理文件夹从一台计算机复制到另一台计算机,这可能会导致问题。

希望有帮助。

快乐编码。