【问题标题】:Cannot resolve symbol Theme.AppCompat after updating com.android.tools.build:gradle to 2.3.0-beta1将 com.android.tools.build:gradle 更新为 2.3.0-beta1 后无法解析符号 Theme.AppCompat
【发布时间】:2017-06-03 04:42:58
【问题描述】:

在将com.android.tools.build:gradle 从项目更新到 2.3.0-beta1 后,我遇到了这个问题。 如果我设置回 2.2.3,Theme.AppCompat 样式会识别。

我不想设置为 2.2.3,因为项目不能超时。

这是错误的打印:

我的项目build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0-beta1'

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

allprojects {
    repositories {
        jcenter()
    }
}

我的应用程序的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    defaultConfig {
        applicationId "com.xxxxxxx.xxxxxxx"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 76
        versionName "1.18.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    useLibrary 'org.apache.http.legacy'
}

buildscript {

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }

    repositories {

        maven {
            url 'https://maven.fabric.io/public'
        }

    }

}

repositories {

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }

    maven {
        url 'https://maven.fabric.io/public'
    }

    flatDir {
        dirs 'libs'
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
        exclude group: 'com.google.android', module: 'support-v4'
    }
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }
    compile(name: 'libctfclient-sdk', ext: 'aar')

    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:support-v13:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.android.support:design:25.1.0'

    compile 'com.github.gabrielemariotti.cards:library:1.8.0'
    compile 'com.github.gabrielemariotti.cards:library-extra:1.8.0'
    compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:0.9.9'
    compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
    compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
    compile 'com.google.zxing:core:3.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.google.android.gms:play-services-analytics:9.8.0'
    compile 'com.github.nkzawa:socket.io-client:0.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
}

按照该错误的顺序,我遇到了这个问题:

我已经试过了:

  • Invalidate Caches\Restart;

  • 将android支持库更新到最新版本;

  • 清理并重建项目;

有没有人知道如何在不将项目的build.gradle 设置为 2.2.3 的情况下解决此问题?

【问题讨论】:

    标签: android build.gradle android-appcompat


    【解决方案1】:

    尝试:文件->“使 Cashes\Restart 无效”

    可能只是android studio的问题

    【讨论】:

    • 我已经做了,但没有成功。我将它添加到问题中,我忘记了
    • 您是否尝试从项目目录中删除 .gradle?两天我的项目就像:无法解析 getResources() 方法。删除 .gradle 后,一切正常。
    • 我还没有。我会试试看。谢谢!!
    【解决方案2】:

    我使用了 android.tools.build:gradle:2.3.0-beta3 并且遇到了同样的问题。我已将 Android Studio 2.2.3 升级到 2.3 beta 2,一切正常。

    【讨论】:

      【解决方案3】:

      正如这个答案中所说的https://stackoverflow.com/a/42765120/3825764

      “构建缓存”在 2.3.0 之后的构建 Android 插件中默认启用。它在项目文件夹之外的构建缓存中创建文件(例如,在 \Users\%username%.android\build-cache 中)。这些文件旨在在您的项目之间通用。

      然后 Android Studio 无法在这些文件中导航。

      您可以在 gradle.properties 文件中禁用构建缓存。只需添加 android.enableBuildCache=false

      【讨论】:

        【解决方案4】:

        File -> Invalidate Caches / Restart 没有解决问题。

        Preferences -> Build, Execution, Deployment -> Gradle 显示使用 Gradle home 选择的本地 gradle 分发:/Applications/Android Studio.app/Contents/gradle/gradle-2.14.1 并显示警告说 gradle 位置是不正确。

        通过选择使用默认 gradle 包装器(推荐)解决了问题。 可能只是指向新的本地分发位置也可以。

        【讨论】:

          猜你喜欢
          • 2022-09-29
          • 2018-11-01
          • 2019-05-19
          • 2021-04-02
          • 2021-10-07
          • 2018-06-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多