0

Google マップ アクティビティを使用して Android Studio で新しいプロジェクトを作成すると、プロジェクトの初期ビルドを行うときに次のエラーが発生します。

マニフェストのマージに失敗しました:属性 application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 も存在します[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). 提案: AndroidManifest.xml:12:5-41:19 の要素に 'tools:replace="android:appComponentFactory"' を追加してオーバーライドします。

追加すると:

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);
    }

Android マニフェスト:

<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 に移行するとうまくいくはずです。これら 2 つのフラグを gradle.properties ファイルに追加してください。Refactor > Migrate to AndroidXAndroidスタジオのメニューバーに移動してリファクタリングします

android.useAndroidX=true
android.enableJetifier=true
于 2020-02-12T03:33:27.887 に答える