Android 资源链接失败 - Daemon : AAPT2 aapt2-3. 2.0-4818971-windows Daemon #0

标签 android android-studio gradle

我把android studio升级到3.2.0,并创建了默认项目。但是编译器报错:

Android resource linking failed
Output:  D:\android1\project\algeria\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:54: error: unexpected element <action> found in <manifest><application><service>.

Command: C:\Users\nthan\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971-windows.jar\82eccc572f5d84358296092db0bec570\aapt2-3.2.0-4818971-windows\aapt2.exe link -I\
    D:\Sdk\platforms\android-26\android.jar\
    --manifest\
    D:\android1\project\algeria\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
    -o\
    D:\android1\project\algeria\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
    -R\
    @D:\android1\project\algeria\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
    --auto-add-overlay\
    --java\
    D:\android1\project\algeria\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
    --custom-package\
    \
    -0\
    apk\
    --output-text-symbols\
    D:\android1\project\algeria\app\build\intermediates\symbols\debug\R.txt\
    --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.0-4818971-windows Daemon #0

我的项目构建 gradle:

buildscript {
repositories {
    jcenter()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'

    // 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'
    }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

我的模块构建 gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "27.0.1"
defaultConfig {
    applicationId ""
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 3
    versionName "2.3"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
buildTypes.each {
    it.buildConfigField 'String', 'handsome', black
}
}
dependencies {
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'
})
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.android.exoplayer:exoplayer:r1.5.3'
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'com.google.firebase:firebase-ads:10.2.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-ads:8.4.0'
testImplementation 'junit:junit:4.12'
}

我的 list :

  <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:windowSoftInputMode="stateAlwaysHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <!--<action android:name="android.intent.action.PHONE_STATE" >-->
            <!--</action>-->
        </intent-filter>
    </activity>
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
    <activity android:name=".InterstitialActivity"></activity>
    <service android:name=".service.ForegroundService" >
        <action android:name="android.intent.action.PHONE_STATE" />
    </service>

</application>

我有最新版本的 android studio,我的项目在升级我的 gradle 之前运行得很好...... 而且我想不出任何办法。只是求助!!

最佳答案

您的 list 代码有问题。 服务标签需要包含 intent-filter 标签 在使用 Action 标签之前! https://developer.android.com/guide/topics/manifest/service-element 解决方案:

<service android:name=".service.ForegroundService" >
<intent-filter> 
        <action android:name="android.intent.action.PHONE_STATE" />
</intent-filter> 
    </service>

关于Android 资源链接失败 - Daemon : AAPT2 aapt2-3. 2.0-4818971-windows Daemon #0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52571396/

相关文章:

android - 如何在 Android SQlite 中添加 bool 列

android - Android Studio 测试中的颜色含义

java - android studio 本地化不翻译

android - 如何在 Android 上解析 "Failed resolution of: Lcom/sun/mail/util/MailLogger"?

android - 如何将 Gallery 中的图像显示到 ImageView?

android - 如何使用 SQL 数据库在 Android 中保存从 Arduino 板接收到的数据?

android - 重新启动时如何使android应用程序返回上一个打开的 Activity ?

android - 来自 Android Studio 的 File.mkdirs 警告

java - Travis CI 和 JUnit with Gradle 找不到类路径资源

android - 在Android Studio中构建Unity项目的问题