1

I'm kind of new to Android development, and I think I may have made a mistake. I've been working with compileSdkVersion 25 in my build.gradle file. But I want my application to be supported for Android 4.1 and higher.

However, when I run my application on a Android 4.1 system, it will immediately shut down (I guess because it's not supported).

I tried to change the compileSdkVersion 25 to compileSdkVersion 16, but this will give a lot of errors (and I know why). It's kind of annoying to start changing every little thing which is not supported in Android 4.1, so..

Question: What is the correct way to downgrade your Android application?

Current build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "xxxx"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
        multiDexEnabled  true
        useLibrary 'org.apache.http.legacy'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.google.firebase:firebase-core:9.8.0'

    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Guido
  • 1,161
  • 3
  • 12
  • 33
  • 1
    The errors are probably caused by incompatible codes from higher version. You might be needing to use some backward compatible codes using support libraries. – Enzokie Mar 20 '17 at 11:26
  • @Enzokie Yes I know that, but I'm trying to find a simple way to do so. – Guido Mar 20 '17 at 11:28
  • *It's kind of annoying to start changing every little thing which is not supported in Android 4.1* sucks, but you have no other option – Tim Mar 20 '17 at 11:29
  • I am afraid that the *simple way don't exists*. – Enzokie Mar 20 '17 at 11:30
  • Compile SDK version says "I want to be using features introduced in up to this platform **but I will make sure my app works on older devices which do not have said features**". Support libraries will help you achieve backward compatibility. Until you post stack trace, don't expect any precise help. – Eugen Pechanec Mar 20 '17 at 12:34
  • Alright I'll take a look into it, and I won't post +300 errors haha :P – Guido Mar 20 '17 at 12:46
  • 1
    @Guido Run `gradlew lint` from terminal and check the output. You can fix most errors in a fashion similar to this: `view.getLayoutDirection()` --> `ViewCompat.getLayoutDirection(view)` – Eugen Pechanec Mar 20 '17 at 12:49

2 Answers2

3

I've been working with compileSdkVersion 25 in my build.gradle file. But I want my application to be supported for Android 4.1 and higher.

Pay attention.
compileSdkVersion is the version of the Android SDK to compile your app with and does not change runtime behavior since your compileSdkVersion is not included in your APK.
It is strongly recommended that you always compile with the latest SDK.
Also it means that using compileSdk = 16 doesn't help you.

Question: What is the correct way to downgrade your Android application?

If the question is how to build an app that can runs also on Android 4.1, the answer in general is to use where it is possibile the support libraries and to check all the methods that require a minSDK > 16.

In your case you should check what is the error in the logcat.
There isn't a simple way to do it.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
-1

For this, set

minSdkVersion 16 

in your build.gradle and run your application with Jelly Bean (API 16) in emulator. But some of the libraries are not supported in API 16. For example, when you want to use wearable widgets support to your application,your API level must be 20 or higher.

Anands23
  • 758
  • 9
  • 19