0

当我使用 Google Maps Activity 在 Android Studio 中创建一个新项目时,我在进行项目的初始构建时收到以下错误:

清单合并失败:来自 [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 的属性 application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) 也存在于[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory)。建议:将 'tools:replace="android:appComponentFactory"' 添加到 AndroidManifest.xml:12:5-41:19 的元素以覆盖。

当我添加:

tools:replace="android:appComponentFactory

在我的AndroidManifest.xml文件中,我收到以下错误:

清单合并失败并出现多个错误,请参阅日志

我在 StackOverflow 上找到了几个潜在的解决方案,但没有一个可行。

我尝试了几种在 StackOverflow 上找到的潜在解决方案,包括:

  • 迁移到 AndroidX

  • 将以下行添加到我的清单

tools:replace="android:appComponentFactory android:appComponentFactory="whateverString"

  • 删除实现com.android.support:appcompat-v7:28.0.0-rc01

主要活动代码

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

安卓清单:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/.
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
4

3 回答 3

1

迁移到 androidX 应该可以解决问题,将这两个标志添加到您的 gradle.properties 文件中。通过进入Refactor > Migrate to AndroidXandroid studio 菜单栏进行重构

android.useAndroidX=true
android.enableJetifier=true
于 2020-02-12T03:33:27.887 回答
0

您需要做的就是更新您的 android studio,一切顺利。我创建了一个新项目,它运行良好。

于 2019-10-10T07:04:03.230 回答
0

答案应该与 AndroidX 相关联,并确保您已将所有支持库迁移到 AndroidX。这将包括设计库。我有同样的问题,一旦我迁移它们就可以了。在此处查看所有可能的库https://developer.android.com/jetpack/androidx/migrate

于 2019-07-20T02:51:00.823 回答