How to create a release signed apk file using Gradle?

Easier way than previous answers: Put this into ~/.gradle/gradle.properties RELEASE_STORE_FILE={path to your keystore} RELEASE_STORE_PASSWORD=***** RELEASE_KEY_ALIAS=***** RELEASE_KEY_PASSWORD=***** Modify your app/build.gradle, and add this inside the android { code block: … signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD // Optional, specify signing versions used v1SigningEnabled true v2SigningEnabled true } } buildTypes { … Read more

What is the difference between compileSdkVersion and targetSdkVersion?

compileSdkVersion The compileSdkVersion is the version of the API the app is compiled against. This means you can use Android API features included in that version of the API (as well as all previous versions, obviously). If you try and use API 16 features but set compileSdkVersion to 15, you will get a compilation error. … Read more

Android Gradle plugin 0.7.0: “duplicate files during packaging of APK”

As of Android Studio version 0.8.14 You should add: android { packagingOptions { exclude ‘META-INF/LICENSE.txt’ exclude ‘META-INF/NOTICE.txt’ exclude ‘…’ } } to your build.gradle file. History: According to comment 14 in this bug: https://issuetracker.google.com/issues/36982149#comment14 this is a bug in v0.7.0 of the Android Gradle plugin, and is due to be fixed soon in 0.7.1. Here … Read more

Is it possible to declare a variable in Gradle usable in Java?

Here are two ways to pass value from Gradle to use in Java; Generate Java Constants android { buildTypes { debug { buildConfigField “int”, “FOO”, “42” buildConfigField “String”, “FOO_STRING”, “\”foo\”” buildConfigField “boolean”, “LOG”, “true” } release { buildConfigField “int”, “FOO”, “52” buildConfigField “String”, “FOO_STRING”, “\”bar\”” buildConfigField “boolean”, “LOG”, “false” } } } You can access … Read more

Automatically accept all SDK licences

UPDATE 2021 This should be the accepted answer as its easy and upto date AndroidSDK can finally accept licenses. Go to Android\sdk\tools\bin yes | sdkmanager –licenses EDIT: as pointed out in the comments by @MoOx, on macOS, you can do yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager –licenses as pointed out in the comments by @pho, @mikebridge and … Read more

Android studio adds unwanted permission after running application on real device

compile ‘com.google.android.gms:play-services:+’ This library will request location permissions, as several pieces of Play Services need it. First, never use +. If you want to allow free-floating patchlevels (e.g., 22.0.+), that’s not completely insane, but using + for the version is insane. Next, consider using one (or more) of the more focused dependencies, rather than the … Read more

DexIndexOverflowException Only When Running Tests

com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, … Read more

Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat

Run gradle -q dependencies (or gradle -q :projectName:dependencies) to generate a dependency report. You should see where r7 is coming from, such as: compile – Classpath for compiling the main sources. +— com.commonsware.cwac:camera-v9:0.5.4 | +— com.actionbarsherlock:actionbarsherlock:4.4.0 | | \— com.google.android:support-v4:r7 | +— com.commonsware.cwac:camera:0.5.4 | \— com.android.support:support-v4:18.0.+ -> 18.0.0 \— com.android.support:support-v4:18.0.+ -> 18.0.0 Then, use the … Read more