使用Google Maps活动创建项目时出现Android Studio错误

使用Google Maps活动创建项目时出现Android Studio错误,android,maps,fragment,manifest,jave,Android,Maps,Fragment,Manifest,Jave,当我在Android Studio中使用Google Maps活动创建一个新项目时,我在进行项目的初始构建时遇到以下错误: 清单合并失败:属性application@appComponentFactoryvalue=android.support.v4.app.CoreComponentFactory,来自[com.android.support:support compat:28.0.0]AndroidManifest.xml:22:18-91 在[androidx.core:core:1.0

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

清单合并失败:属性application@appComponentFactoryvalue=android.support.v4.app.CoreComponentFactory,来自[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>

答案应该与AndroidX联系在一起,并确保所有支持库都迁移到AndroidX。这将包括设计库。我也遇到过同样的问题,一旦我迁移了它们,问题就解决了。在这里查看所有可能的库

你需要做的就是更新你的android studio,你就可以开始了。我创建了一个新项目,它运行良好。

迁移到androidX应该可以做到这一点,将这两个标志添加到gradle.properties文件中。通过进入android studio菜单栏中的重构>迁移到AndroidX进行重构

android.useAndroidX=true
android.enableJetifier=true

事实上,我宁愿不使用androidx。这只是关于另一个问题的建议,我认为值得一试。