如何在Android 9上支持Apps

时间:2019-03-21 10:06:20

标签: java android gradle

我必须构建一个应用程序,它支持直到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要求我将最低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)中正常运行

2 个答案:

答案 0 :(得分:0)

按如下所示更改您的配置        buildToolsVersion = "21.0.1" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 27 supportLibVersion = "28.0.0"

答案 1 :(得分:0)

首先,您需要通过定位到API级别28来设置应用 build.gradle以支持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+的更改。