【问题标题】:Cannot find symbol R when Updating to Android 3.1.3更新到 Android 3.1.3 时找不到符号 R
【发布时间】:2018-07-12 07:00:09
【问题描述】:

昨天我将 Android 更新到 Android 3.1.3,一切都还不错,直到今天我创建了一个新的 Empty Activity 并且在“AppCompatActivity”上显示错误“找不到符号”,所以我搜索并阅读它与“build.gradle”有关,所以我一直在更新库并得到不同的错误,最新的一个是对象“R”无法解析符号。所以这就是我所拥有的。

我已经多次尝试解决它(如您在代码中看到的 cmets),但到目前为止我还没有解决它。请帮我!

还有一个部分,Android 建议我将 gradle.properties # org.gradle.parallel=true 从 false 更改,但它也不起作用。

build.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        //classpath 'com.android.tools.build:gradle:2.1.3'
        //classpath 'com.android.tools.build:gradle:3.2.0-alpha17'
        //classpath 'com.android.tools.build:gradle:3.1.3'
        //classpath 'com.google.gms:google-services:3.2.0'
        //classpath 'com.android.tools.build:gradle:3.1.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            //name 'Google'
        }
    }
}

依赖

android {
    compileSdkVersion 23
    buildToolsVersion '24.0.2'

    defaultConfig {
        applicationId "com.example.dell.getspeed"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    //compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile 'net.gotev:uploadservice:2.1'
    compile 'com.mcxiaoke.volley:library-aar:1.0.1'
    compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'

    /*implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'


    /*implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    //implementation 'com.android.support:appcompat-v7:27.1.0'
    //implementation 'com.android.support:design:26.4.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.github.anastr:speedviewlib:1.2.0'
    compile 'com.android.support:design:25.4.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    //compile 'com.android.support.constraint:constraint-layout:1.1.2'*/
}

gralde-wrapper.propierties

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

日志: Logs

【问题讨论】:

  • 尝试清理您的项目并重建它。
  • 转到文件> 无效并重新启动,然后单击无效并重新启动
  • 我已经清理并重建了它,但它没有用@Ankita
  • 我刚做了,但没用@Priyank

标签: android android-studio gradle cannot-find-symbol


【解决方案1】:

关闭项目并再次导入。今天为我工作。

由于某种原因,这些属性在 26 个库中不再存在。为了增加这些库,您还必须将 compileSdk 增加到 27。很可能您还必须下载 sdk 27​​

短版,后续继续应用`graddle``

compile 更改为implementation

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "cl.cutiko.testingupdate"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

build.gradle(项目)

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

【讨论】:

  • 当我这样做时,我得到了这个日志:“找不到 Gradle DSL 方法:'google()' 可能的原因:
    • 项目 'GetSpeed' 可能使用的是 Android 版本不包含该方法的 Gradle 插件(例如 1.1.0 中添加了“testCompile”)。将插件升级到 3.1.3 版本并同步项目
    • 项目“GetSpeed”可能正在使用一个版本不包含该方法的 Gradle。打开 Gradle 包装文件
    • 构建文件可能缺少 Gradle 插件。应用 Gradle 插件
    • "
【解决方案2】:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

classpath 'com.android.tools.build:gradle:3.1.3'

compileSdkVersion 27
minSdkVersion 16
targetSdkVersion 27

implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.android.support:design:23.4.0'
implementation 'com.android.support:support-v4:23.4.0'
implementation 'com.android.support:recyclerview-v7:23.4.0'

文件 - 使缓存无效/重新启动 - 无效并重新启动

【讨论】:

  • 添加这个时,错误仍然存​​在。并将日志更新到帖子中
【解决方案3】:

关闭当前项目并再次重新打开它并重建解决方案。大多数时候通过重建解决方案, “R无法解决”的问题可以解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多