2

I'm working in an app. The app works in Android 7.x.x but when I try to run the app in the Android 5.x.x app crashed. I think this is happening because the compileSdkVersion is API 25. When I try to to change this to API 21 (ANDROID 5), I have some errors. What can I do to my app work in Android 5?

ps: I don't know if the app is working in Android 6, but probably is not working.

build.gradle:

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId "project.id"
    minSdkVersion 16
    targetSdkVersion 16
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

When I try to change the compileSdkVersion to API 21, I have this errors:

Error:resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
Error:resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
Error:resource android:style/TextAppearance.Material.Widget.Button.Inverse not found.
Error:resource android:style/Widget.Material.Button.Colored not found.
Error:failed linking references.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.

Failed to execute aapt

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
Tony Starkus
  • 556
  • 2
  • 8
  • 25
  • Not sure about the problem, but you should take a look at [compile & targetSDK](https://stackoverflow.com/a/26694276/5359331). Your targetSDK should always be set to the newest Android to ensure that the application works on the newest Android phones. – Tobias Ettrup Mølbak Nov 15 '17 at 14:17
  • No. You can set it much lower. Please read your link. @Tobias Hvass Mølbak – greenapps Nov 15 '17 at 14:47

1 Answers1

4

Your compileSdkVersion MUST match the support library. So change it into 26 in your build.gradle

compileSdkVersion 26
buildToolsVersion '26.0.2'
compile 'com.android.support:appcompat-v7:26.0.2'

targetSdkVersion is supposed to indicate that you have tested your app on (presumably up to and including) the version you specify. Optional, but it SHOULD be 26 too.

It could also error about support library that can cause app to force close. See: InflateException with FloatingActionButton from Official Design Library

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
  • [Not necessarily](https://stackoverflow.com/a/24523113/5359331), as the buildtools supports older versions. – Tobias Ettrup Mølbak Nov 15 '17 at 14:22
  • @TobiasHvassMølbak no, Your compile SDK version **must** match the support library's major version. See: https://stackoverflow.com/a/32075678/5282585 – nhoxbypass Nov 15 '17 at 14:24
  • 1
    I miss read, you statement. Guess the build.gradle got me thinking of the buildtoolsversion (as I wrote about in my comment). – Tobias Ettrup Mølbak Nov 15 '17 at 14:25
  • Right, now i don't have compile error :) But the app still force close in android 5. I have a device with android 7 and a virtual device with android 8.1.1 and the app work fine, but with the virtual device running android 5 the app force close.... – Tony Starkus Nov 15 '17 at 15:55
  • After change as I wrote above @TonyStarkus? Did you try running apps on Android 5.1 or Android 4.4? – nhoxbypass Nov 15 '17 at 15:58
  • I created another app with API 16:JELLY BEAN. The app is running fine in android 5. So i back to my app and tried to run again but no sucess, the app still force close. And this is the app actual confgs: compileSdkVersion 26 / minSdkVersion 16 / targetSdkVersion 26 – Tony Starkus Nov 15 '17 at 16:18
  • " with API 16:JELLY BEAN" You mean targetSdk or minSdk – nhoxbypass Nov 15 '17 at 16:25
  • minSdkVersion is 16. The targetSdk is 26 – Tony Starkus Nov 15 '17 at 16:32
  • "I created another app with API 16:JELLY BEAN. The app is running fine in android 5": Can you please provide config of this app? – nhoxbypass Nov 15 '17 at 16:35
  • compileSdkVersion 26 / minSdkVersion 16 / targetSdkVersion 26 / I put the same config in the other app, but no sucess. – Tony Starkus Nov 15 '17 at 16:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159082/discussion-between-nhoxbypass-and-tony-starkus). – nhoxbypass Nov 15 '17 at 16:53