【问题标题】:How to use com.android.support.AppCompatActivity when using com.google.android.material:material:1.0.0-alpha3?使用com.google.android.material:material:1.0.0-alpha3时如何使用com.android.support.AppCompatActivity?
【发布时间】:2018-07-07 08:33:18
【问题描述】:

com.google.android.material:material:1.0.0-alpha3 需要 28 的最低 sdk 版本,com.android.support.AppCompatActivity 使用 27。所以当我尝试运行程序时出现错误。

另外,在官方材料设计文档中,声明com.android.materialcom.android.support 不应该一起使用。

因此,当我删除 com.android.support.AppCompatActivity 时,编译器无法解析 AppCompatActivity。我该怎么办?

更新 我能够通过删除 com.google.android 来解决异常。出现错误,因为 com.google.android 不能与 com.android.support 一起使用。

但我现在收到此错误: 失败 [INSTALL_FAILED_OLDER_SDK:在 installPackageLI 期间解析失败:/data/app/vmdl714979868.tmp/base.apk(在二进制 XML 文件第 7 行):需要开发平台 P,但这是一个发布平台。]

apply plugin: 'com.android.application'

android {
compileSdkVersion 'android-P'
defaultConfig {
    minSdkVersion 21
    targetSdkVersion 'P'
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

//implementation 'com.google.android.material:material:1.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- 
core:3.0.2'
testImplementation 'junit:junit:4.12'

}

apply plugin: 'com.google.gms.google-services'

【问题讨论】:

    标签: android user-interface


    【解决方案1】:

    您还需要使用 AppCompat 库的 alpha 版本。

    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.google.android.material:material:1.0.0-alpha1'
    implementation 'com.android.support:design:28.0.0-alpha1'
    

    【讨论】:

    • org.gradle.api.tasks.TaskExecutionException: 任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' 执行失败
    • 这就是发生的事情
    • @BarathR 分享 gradle 文件
    • 我已经分享了 gradle 和我当前问题的更新
    • @BarathR 你应该检查 compileSdkVersion = 28. 而不是 P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 2017-06-16
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    相关资源
    最近更新 更多