【问题标题】:Android resource compilation failed after updating android studio更新android studio后android资源编译失败
【发布时间】:2018-12-04 08:43:25
【问题描述】:

我刚刚将我的 android studio 更新到了 3.2.1 版本,并通过 android studio 将我的 gradle 更新到了最新版本,但是构建项目面临这个错误:

Android 资源编译失败输出: D:\projects\myProject\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2577: 错误:内部元素必须是资源引用或 空的。 D:\projects\myProject\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2585: 错误:内部元素必须是资源引用或 空。

命令: C:\Users\Hamed.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\ea639d8248f3ebb66b449dfd3b6a9a07\aapt2-3.2.1-4818971-windows\aapt2.exe 编译 --legacy \ -o \ D:\projects\myProject\app\build\intermediates\res\merged\debug\ D:\projects\myProject\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml 守护进程:AAPT2 aapt2-3.2.1-4818971-windows 守护进程#0

并且在它说有错误的行中,此代码存在:

<item name="googledefaultpass" type="id">123456789</item>

怎么了?我搜索的解决方案是this,但结构是一样的。

我已经更新了我所有的库。

应用级分级:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.my.project"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "0.7"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [onesignal_app_id               : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "REMOTE"]
    }
    applicationVariants.all { variant ->
        variant.resValue "string", "versionName", variant.versionName
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    jcenter()
}
dependencies {
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    //    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //    compile 'im.crisp:crisp-sdk:0.1.10'
    implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
    implementation 'com.stephentuso:welcome:1.4.1'
    implementation 'co.ronash.android:pushe-base:1.4.0'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    //    compile 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation('io.socket:socket.io-client:1.0.0') {
        // excluding org.json which is provided by Android
        exclude group: 'org.json', module: 'json'
    }
    implementation 'com.android.volley:volley:1.1.0'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}


configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '28.+'
            }
        }
    }
}

apply plugin: 'com.google.gms.google-services'

项目级等级:

repositories {
        google()
        maven { url 'https://maven.google.com' }
        jcenter()
        mavenCentral()
        buildscript {
            repositories {
                google()
                jcenter()
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:3.2.1'
                classpath 'com.google.gms:google-services:4.0.1'
            }
        }

        allprojects {
    }
}

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

更新

我使缓存无效并重新启动Android Studio,问题解决了,但我遇到了以下错误:

> Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.71.
> Searched in the following locations:
>     https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.2.71/kotlin-stdlib-jdk8-1.2.71.pom
>     https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.2.71/kotlin-stdlib-jdk8-1.2.71.jar
>     https://maven.google.com/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.2.71/kotlin-stdlib-jdk8-1.2.71.pom
>     https://maven.google.com/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.2.71/kotlin-stdlib-jdk8-1.2.71.jar
> Required by:
>     project : > com.android.tools.build:gradle:3.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > com.android.tools.build:builder:3.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > com.android.tools.lint:lint-gradle-api:26.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > com.android.tools.build:gradle-api:3.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > androidx.databinding:databinding-compiler-common:3.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > com.android.tools.build:builder:3.2.1 >
> com.android.tools:sdk-common:26.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > com.android.tools.build:builder:3.2.1 >
> com.android.tools:common:26.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > com.android.tools.build:builder:3.2.1 >
> com.android.tools.build:manifest-merger:26.2.1
>     project : > com.android.tools.build:gradle:3.2.1 > com.android.tools.build:builder:3.2.1 >
> com.android.tools:sdklib:26.2.1 > com.android.tools:repository:26.2.1

关键是我根本没有使用 Kotlin。我将 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71" 添加到 gradle 依赖项,但出现了同样的错误。我在整个项目中搜索了Kotlin,但除了一些replay_pid1632.log 文件之外什么都没有。

tnx

【问题讨论】:

  • 您是否尝试过使缓存无效并重新启动?
  • 删除 Project->app ->build 文件夹。如果您无法直接删除它,则可以删除所有内部文件夹,例如 generated、intermedias、outputs 等...,然后执行 invalid caches / Restart。
  • @Alex 你会检查我的帖子更新吗? tnx
  • @RumitPatel 你会检查我的帖子更新吗? tnx
  • 我不明白为什么您会收到 kotlin 错误。你可以根据我的第一条评论再做一次。或者您可以尝试将所有 gradle 依赖项更新为最新版本。

标签: android android-studio gradle android-gradle-plugin build.gradle


【解决方案1】:

resource-typeid不得有值。

因此,改变:

<item name="googledefaultpass" type="id">123456789</item>

到任一:

<item name="googledefaultpass" type="integer">123456789</item>
<item name="googledefaultpass" type="string">123456789</item>

或删除条目并获取AccountManager 的帐户,而不是。

关于kotlin-stdlib-jdk8 依赖;它在存储库mavenCentral() 中可用:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.10"

也许还可以删除这个重复的依赖项:

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

【讨论】:

    【解决方案2】:

    我认为您不应该为 id 类型的资源赋值。改变

    <item name="googledefaultpass" type="id">123456789</item>
    
    to 
    
    <item name="googledefaultpass" type="id"/>
    

    【讨论】:

    【解决方案3】:

    就我而言,问题是我忘记在 StringArray 的项目中转义撇号。

    所以在我的strings.xml 我改变了

    <string-array name="questions">
        <item>What's the weather today?</item>
    </string-array>
    

    <string-array name="questions">
        <item>What\'s the weather today?</item>
    </string-array>
    

    现在它构建得非常好。

    【讨论】:

    • 这是我的问题,也节省了我几个小时,哈哈
    【解决方案4】:

    尝试添加

    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71'
    

    在项目级别的gradle依赖里面,然后添加

    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71'
    

    在您的应用级别 gradle 中。 也许您的某个库需要 kotlin 插件。

    【讨论】:

      猜你喜欢
      • 2019-03-02
      • 2019-06-27
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 2021-12-25
      相关资源
      最近更新 更多