【问题标题】:How to make Apps support on Android 9如何使应用程序支持 Android 9
【发布时间】:2019-03-21 10:06:20
【问题描述】:

我必须构建一个应用程序,它支持到 android 9 gradle 设置看起来像

compileSdkVersion 25
buildToolsVersion "26.0.0"
useLibrary 'org.apache.http.legacy'
defaultConfig {
    applicationId "com.sdept.company.starmobile"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 6

    versionName "1.6"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.code.gson:gson:2.4'
//    implementation 'com.google.firebase:firebase-core:16.0.1'
compile 'org.apache.httpcomponents:httpcore:4.2.4'
compile 'org.apache.httpcomponents:httpmime:4.3'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.zxing:core:3.2.1'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.firebase:firebase-messaging:11.0.4'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

上述设置在应用调试版本时运行良好,但是当我尝试在 Google Play 中上传时,google play 要求我将 min targetSDKVersion 更改为 28。所以我将其更改为这个

compileSdkVersion 25
buildToolsVersion "26.0.0"
useLibrary 'org.apache.http.legacy'
defaultConfig {
    applicationId "com.sdept.company.starmobile"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 6

    versionName "1.6"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.code.gson:gson:2.4'
//    implementation 'com.google.firebase:firebase-core:16.0.1'
compile 'org.apache.httpcomponents:httpcore:4.2.4'
compile 'org.apache.httpcomponents:httpmime:4.3'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.zxing:core:3.2.1'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.firebase:firebase-messaging:11.0.4'
testCompile 'junit:junit:4.12'
//    compile 'com.squareup.retrofit2:retrofit:2.1.0'
// JSON Parsing
//    compile 'com.google.code.gson:gson:2.6.1'
//    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
//    compile 'com.google.android.gms:play-services-appindexing:11.0.4'
}
apply plugin: 'com.google.gms.google-services'

在 playstore 上上传时成功,但应用程序无法在 android 9 上运行,我必须更改的代码部分在哪里才能在 Android 9 (Pie) 中正常运行

【问题讨论】:

  • compileSdkVersion 28 buildToolsVersion "28.0.0"
  • 更正compileSdkVersion和构建工具版本
  • @Athira 我写的依赖怎么样,它也需要改变吗?
  • 是的。如果您发现查找正确版本的问题,请转到文件-> 项目结构-> 应用程序-> 依赖项-> 库依赖项-> 选择库

标签: java android gradle


【解决方案1】:

改变你的配置如下 buildToolsVersion = "21.0.1" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 27 supportLibVersion = "28.0.0"

【讨论】:

  • 依赖关系怎么样,应该改变吗?
【解决方案2】:

首先,您需要设置您的 应用 build.gradle 以支持 API 级别 28 的 Android 9,目标为 API 级别 28。因此,更改您的build.gradle 变成这样:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 28
  buildToolsVersion "28.0.3"


  defaultConfig {
    minSdkVersion 15
    targetSdkVersion 28

     ...
  }

  ...

}

...

dependencies {
    ...
    implementation 'com.android.support:appcompat-v7:28.0.0'
}

第二,请确保您使用的是 https 而不是 http。详情请看我之前的回答: Internet permission not working in oreo and pie

请访问Behavior changes: apps targeting API level 28+ 了解有关 API 级别 28+ 更改的详细信息。

【讨论】:

    猜你喜欢
    • 2019-06-13
    • 2013-06-08
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多