【问题标题】:No resource identifier found for attribute 'appComponentFactory' in package 'android'在包“android”中找不到属性“appComponentFactory”的资源标识符
【发布时间】:2018-05-10 05:25:56
【问题描述】:

我使用谷歌材料设计作为https://material.io/develop/android/docs/getting-started/ 但是当同步项目时我有以下错误

在包“android”中找不到属性“appComponentFactory”的资源标识符 Message{kind=ERROR, text=No resource identifier found for attribute 'appComponentFactory' in package 'android', sources=[\?\E:\Projects\xoxo-android\app\build\intermediates\manifests\full\debug\ AndroidManifest.xml:17],原始消息=,工具名称=Optional.of(AAPT)}

这是我的 build.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.example.official2.xoxo"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.support:design:26.0.1'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
    compile 'com.wang.avi:library:2.1.3'
    compile 'com.mikhaellopez:circularimageview:3.0.2'
    compile 'com.droidninja:filepicker:1.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:cardview-v7:26.0.1'
    compile 'com.github.ganfra:material-spinner:1.1.1'
    compile 'com.google.android.material:material:1.0.0-alpha1'
}

这是 manifest.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.official2.xoxo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="26" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:name="droidninja.filepicker.FilePickerDelegate"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.official2.xoxo.activity.LoginActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.official2.xoxo.activity.RegisterActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:windowSoftInputMode="adjustPan" />
        <activity
            android:name="com.example.official2.xoxo.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop" />
        <activity
            android:name="com.example.official2.xoxo.activity.RegisterInfo"
            android:screenOrientation="portrait" />
        <activity android:name="com.example.official2.xoxo.activity.Registration_shop" />
        <activity
            android:name="com.example.official2.xoxo.activity.Product_Dashboard"
            android:label="@string/title_activity_product__dashboard"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name="com.example.official2.xoxo.activity.AddService" />

        <!--
 ATTENTION: This was auto-generated to add Google Play services to your project for
     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information.
        -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity android:name="com.example.official2.xoxo.activity.SellerProfile" />
        <activity android:name="com.example.official2.xoxo.activity.Services" />
        <activity
            android:name="com.example.official2.xoxo.activity.AddProduct"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateVisible|adjustResize" />
        <activity
            android:name="com.example.official2.xoxo.activity.ProductProfileActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name="com.example.official2.xoxo.activity.AddImagesActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name="droidninja.filepicker.FilePickerActivity"
            android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >
        </activity>

        <meta-data
            android:name="android.support.VERSION"
            android:value="26.0.1" />
    </application>

</manifest>

如何解决这个错误?

【问题讨论】:

  • 错误出现在合并的清单中,因此它可能是您引用该资源的依赖项之一。把文件 E:\Projects\xoxo-android\app\build\intermediates\manifests\full\debug\AndroidManifest.xml 的内容贴出来看看是什么问题。
  • 感谢您的建议。我使用默认设计方法开发了这个应用程序。无论如何,当发生上述错误时,此清单文件的值为“appComponentFactory”。我使用记事本打开了这个清单文件并删除了这个“appComponentFactory”行并保存了它。然后我构建了我的应用程序,再次生成了这个错误。上面的行再次出现在清单文件中。所以删除那行时我还没有构建我的代码。
  • 该文件由 gradle 插件自动生成,它是您的 AndroidManifest 和您的依赖项的 AndroidManifests 的合并。这就是为什么当您编辑它时,它仍然会被修改并且该行将回到那里。该行必须来自您的依赖项之一 - 发布内容,以便我们确定它是哪一个。
  • 研究那个字符串,它看起来也是一个新的 ApplicationInfo 字段,以 P 开头。确保您的目标 API 是 P(您需要使用 Android P Developer Preview)。

标签: android


【解决方案1】:

试试这个代码:

cordova plugin add cordova-android-support-gradle-release --variable ANDROID_SUPPORT_VERSION=27.+

【讨论】:

  • 这个ANDROID_SUPPORT_VERSION的目的是什么?
  • @devnosaur 它将安装“com.android.support”组的依赖项,其版本由 ANDROID_SUPPORT_VERSION 提供。前任。它将安装依赖 'com.android.support:support-v4' 版本为 27.+。
  • 我必须这样做删除Android平台并重新添加它。
【解决方案2】:

我有同样的错误。在我的情况下,它是由使用+(即"com.android.support:support-v4:27+")指定的依赖关系引起的,使其在使用 API 级别 27 时使用 Android P 依赖关系。

将它们替换为特定版本(例如"com.android.support:support-v4:27.1.1")解决了错误

【讨论】:

  • 在 project.properties 文件中
  • @self.name 是的,别忘了那个
【解决方案3】:

Armysir 回答的一个小问题。我使用了这个步骤:

1.将这些行添加到您的 app/build.gradle:

configurations.all {
  resolutionStrategy.force 'com.android.support:support-v4:26.1.0'
}

2.在AndroidManifest.xml文件中添加一行application-tag:

tools:remove="android:appComponentFactory"

【讨论】:

  • 我认为最好解释添加 configuration.all 代码块的确切位置。它应该在allprojects{ repositories{ .... here }}里面
  • 另外,在 AndroidManifest.xml 的 标签中添加 xmlns:tools="schemas.android.com/tools"。
【解决方案4】:

失败原因

com.google.android.material:materialandroidx 的一部分,您不能在同一个项目中同时使用支持库和androidx。 Android 28.0.0 之后将不再更新支持库。

见@Android support 28.0.0 release notes

这将是 android.support 下的最后一个功能版本 打包,并鼓励开发者迁移到 AndroidX 1.0.0

解决方案

对我来说,解决方案是将我的应用程序迁移到 androidx。我发布了一个 answer 以了解和迁移 androidx 包。 Official migrate documentation也写的很好。

或者

您可以将这些行放入gradle.properties 文件中。

android.useAndroidX = true
android.enableJetifier = true

【讨论】:

    【解决方案5】:

    我遇到了同样的错误。需要 2 天 :(

    转到文件 ==>设置==>构建、执行、部署 ==>Gradle ==>去掉离线工作的标记

    希望对你有帮助

    【讨论】:

      【解决方案6】:

      我在 react-native 项目中遇到此错误,并将 google play 版本代码添加到 gradle.properties 工作。

      googlePlayServicesVersion=12.0.1

      【讨论】:

        【解决方案7】:

        尝试了@Hudson 的回答,但没有奏效。然后发现是因为 FCM 插件的问题,所以我删除了插件并添加了更新的插件,然后再次构建。

        cordova plugin remove cordova-plugin-fcm
        
        cordova plugin add https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated
        

        【讨论】:

        • 当其他解决方案失败时,这个解决方案就像一个魅力
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多