android - Android Studio 中的 Gradle 依赖项

标签 android android-studio firebase-realtime-database

android studio 中的 gradle 文件出错。

  apply plugin: 'com.android.application'

应用插件:'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.mih.demo2"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    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'
}

实现“com.android.support:appcompat-v7:28.0.0”时出错

指导我在android studio中解决这个错误。我搜索了很多但找不到解决方案。 enter image description here

最佳答案

将这些标志放入您的 gradle.properties 中:

android.useAndroidX=true
android.enableJetifier=true

然后为 compileSdkVersion 和 targetSdkVersion 使用 SDK 版本 28:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.mih.demo2"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-core:17.2.0'
    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'
}

它工作正常!

关于android - Android Studio 中的 Gradle 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58046071/

相关文章:

java - 如何通过 URL 从 firebase 数据库下载音频文件 mp3 或 mp4 或 mpeg

ios - Firebase runTransactionBlock 错误 maxretry

android - 使用调试 keystore 在 Google Play 上发布 APK

android - 将数据从免费应用程序数据库导入付费应用程序数据库

Android PopUpWindow - 如何设置边距?

android - 人像图片上传到服务器后旋转90度

android-studio - 复制旧项目时,如何制作 Android Studio "forget"旧文件路径?

android - 如何使用Gradle库在Android中使用自定义字体?

android - 将 ServerValue.TIMESTAMP 转换为日期

android - 如果我可以将 Flow 和 StateFlow 与生命周期范围\viewLifecycleOwner.lifecycleScope 一起使用,那么在 ViewModel 中使用 LiveData 有什么意义