2

First of all, this is my first app development.

All these while I am building my app based on

compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
    minSdkVersion 23
    targetSdkVersion 25
}


dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:support-v4:26.0.0-alpha1'
}

Everything was perfect. No error.

Errors starts occurring when I decided to change sdk to 19.

compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion "26.0.1"
defaultConfig {
    applicationId "vinnito.plando"
    minSdkVersion 19
    targetSdkVersion 19

Errors that I got after changing SDK version

The reason I want to change it to 19 is because of my phone Note 2 which I wish to use as tool to debug my app. I know there are emulators available but I do really want to run the app in an actual device.

I wanted to add dependencies for SDK 19 but i cant find any. All of them are SDK 26. In my SDK Manager, i downloaded SDK 19 and above already though..

Library Dependencies

Anyone knows how can i make this sourcecode able to run in SDK 19 without major change of code or i have no choice?

Thanks in advance.

Vinc
  • 25
  • 1
  • 4

3 Answers3

1

If you want to use the support libraries v.26 first all use:

compileSdkVersion 26

You can't compile with api 19.

Then use a stable version:

compile 'com.android.support:recyclerview-v7:26.1.0
//....do the same for the other libraries.

Pay attention because v.26.x.x requires the maven google repo.

Finally if you want to support devices with api 19 just use:

defaultConfig {
    minSdkVersion 19
}

Keep in mind that you can use the support libraries v26 also on devices with api 19.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thx alot for the explanation Gabriele! – Vinc Nov 12 '17 at 20:17
  • Hi @Vinc if this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Gabriele Mariotti Nov 13 '17 at 07:32
0

You should change only minSdkVersion to 19 for testing purposes. It is bad practise to downgrade targetSdkVersion and it is not necessary.

Your gradle file should look like this:

compileSdkVersion 27
buildToolsVersion "26.0.2"

defaultConfig {
    minSdkVersion 19
    targetSdkVersion 27
}

ext {
    androidSupportVersion = '27.0.0'
}

dependencies {
    compile fileTree ( include: ['*.jar'], dir: 'libs' )
    compile "com.android.support:appcompat-v7:$androidSupportVersion"
    compile "com.android.support:design:$androidSupportVersion"
    compile "com.android.support:recyclerview-v7:$androidSupportVersion"
    compile "com.android.support:support-v4:$androidSupportVersion"
}
mac229
  • 4,319
  • 5
  • 18
  • 24
  • Yes. I did change the minSdkVersion to 19 but whenever i try on 19, it has tons of errors – Vinc Nov 12 '17 at 18:41
  • Have you changed only minSdkVersion? If yes please update your gradle file in main post – mac229 Nov 12 '17 at 18:49
  • @mac229 it's not bad practice to set minSdkVersion to any version unless code requires a minimum threshold for some features, even then make same version checks to use methods or libraries and it would be fine. It's also not right to say change only for debuging purposes and it's not necessary. It can be necessary to cover more percentage of the market. Android 19 and below are 10% percent of the active device on the market. – Thracian Nov 12 '17 at 18:53
  • Oh god. I have written it is bad practise to downgrade TARGET sdk version. The same situation is with other libraries. It is obvious you should cover most devices as you can. – mac229 Nov 12 '17 at 19:20
  • 1
    Yes. It works after changed minSdkVersion to 19 and the rest to 26. Guessed my mistake is that i set every of it to 19 assuming to run on API 19 requires targetsdkversion 19. Thanks alot for the help! – Vinc Nov 12 '17 at 20:20
  • @Vinc No problem, if I helped you, you should upvote my answer and check as correct answer :) – mac229 Nov 12 '17 at 21:00
0

You can remove buildToolsVersion "26.0.1", it's not necessary after Android 3.0. Setting minSdkVersion 19 suffice no need to change targetSdkVersion to 19. I use Android 4.4 for testing but it does not work with com.android.support:appcompat-v7:26.0.0 and above because of it, i'm using 25.x.x version of app-compat and design libraries.I also add my gradle to be more clear, you also don't need to compile recyclerview explicitly, it's included inside design library.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 21
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:design:25.4.0'
    compile 'com.android.support:cardview-v7:25.4.0'
    compile 'com.android.support:appcompat-v7:25.4.0'
}
Thracian
  • 43,021
  • 16
  • 133
  • 222
  • Yeap. Changed minSdkVersion to 19 and it able to run in emulator API 19 now. Will try on the actual device soon! Thx for the advice =) – Vinc Nov 12 '17 at 20:21