如何解决:'com.xxx.xxxx.MainActivity' 不可分配给 'android.app.Activity' less

How to fix : 'com.xxx.xxxx.MainActivity' is not assignable to 'android.app.Activity' less

我无法 运行 我的应用程序,因为我的清单文件中有问题。它说 : 'com.diridou.mescoiffeurs.MainActivity' 不能分配给 'android.app.Activity' less... (Ctrl+F1) 检查信息:验证 Android XML 文件

中的资源引用

MainActivity 扩展了 AppCompatActivity,但我无法解析 AppcompactActivity

我也没有毕业问题。

我补充说: 1°

android.enableJetifier=true
android.useAndroidX=true

在我的 graddle.properties

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.diridou.mescoiffeurs">

    <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"
        tools:ignore="GoogleAppIndexingWarning">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

public class MainActivity extends AppCompatActivity {
}

我的 gradle 文件看起来像:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.diridou.mescoiffeurs"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    /*Dependencies de base */
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    /*Firebase*/
    implementation 'com.google.firebase:firebase-firestore:20.1.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
}

在您的 gradle.properties 中,您将标志设置为使用 AndroidX,但是,您没有导入任何 AndroidX 资源。相反,您正在使用支持依赖项。要解决此问题,请在您的 build.gradle 中检查此 link 是否有您声明的任何依赖项,并将它们替换为相应的 androidx 依赖项。

MainActivity 完全没有任何作用...

您必须提供一个 public 构造函数 - 重写方法 onCreate().

是很常见的

此外,所有这些 com.android.support 依赖项都需要手动替换;

当前版本的 Firebase 在内部使用 androidx(这使得 Jetifier 无用)。