I want to build android app and start signing it.
For that I need to have Release version of apk. Google documentation suggests only Eclipse and ant ways to have release builds: http://developer.android.com/tools/publishing/app-signing.html#releasecompile
However I cannot find how to force gradle build release version of apk. build.gradle does not give any hints either. gradlew tasks suggests, that there is no install Release configuration, but uninstall release exists:
Install tasks
-------------
installDebug - Installs the Debug build
installTest - Installs the Test build for the Debug build
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build
uninstallRelease - Uninstalls the Release build
uninstallTest - Uninstalls the Test build for the Debug build
My build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/android-support-v4.jar')
compile project(":libraries:ActionBarSherlock")
compile project(":libraries:CollabsibleSearchMenu")
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
What I am missing?
open the Build Variants pane, typically found along the lower left side of the window:
set debug to release
shift+f10 run!!
then, Android Studio will execute assembleRelease task and install xx-release.apk to your device.
in the latest version of android studio, you can just do:
./gradlew assembleRelease
or aR for short. This will produce an unsigned release apk. Building a signed apk can be done similarly or you can use Build -> Generate Signed Apk in Android Studio.
See the docs here
Here is my build.gradle for reference:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
}
}
No need to update gradle for making release application in Android studio.If you were eclipse user then it will be so easy for you. If you are new then follow the steps
1: Go to the "Build" at the toolbar section.
2: Choose "Generate Signed APK..." option.
3:fill opened form and go next
4 :if you already have .keystore or .jks then choose that file enter your password and alias name and respective password.
5: Or don't have .keystore or .jks file then click on Create new... button as shown on pic 1 then fill the form.
Above process was to make build manually. If You want android studio to automatically Signing Your App
In Android Studio, you can configure your project to sign your release APK automatically during the build process:
On the project browser, right click on your app and select Open Module Settings.
On the Project Structure window, select your app's module under Modules.
Click on the Signing tab.
Select your keystore file, enter a name for this signing configuration (as you may create more than one), and enter the required information.
Figure 4. Create a signing configuration in Android Studio.
Click on the Build Types tab.
Select the release build.
Under Signing Config, select the signing configuration you just created.
Figure 5. Select a signing configuration in Android Studio.
4:Most Important thing that make debuggable=false at gradle.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.txt'
debuggable false
jniDebuggable false
renderscriptDebuggable false
zipAlignEnabled true
}
}
visit for more in info developer.android.com
To activate the installRelease task, you simply need a signingConfig. That is all.
From http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Android-tasks:
Finally, the plugin creates install/uninstall tasks for all build
types (debug, release, test), as long as they can be installed (which
requires signing).
Here is what you want:
Install tasks
-------------
installDebug - Installs the Debug build
installDebugTest - Installs the Test build for the Debug build
installRelease - Installs the Release build
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build
uninstallDebugTest - Uninstalls the Test build for the Debug build
uninstallRelease - Uninstalls the Release build <--- release
Here is how to obtain the installRelease task:
Example build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId 'demo'
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName '1.0'
}
signingConfigs {
release {
storeFile <file>
storePassword <password>
keyAlias <alias>
keyPassword <password>
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
This is a procedure to configure run release version
1- Change build variants to release version.
2- Open project structure.
3- Change default config to $signingConfigs.release
To compile with release build as shown below:
Related
I used to generate a signed apk from Android Studio and everything was working well until I updated Android Studio to 3.3. It generates an apk but after I try to install it, it says: App Not Installed!
My Trial was by:
Click on build
Generate Signed Apk
Choose APK and click Next
Insert the Key Store Path, Key Store Password, Key Alias, Key Password
Click Next
Choose Release Variant
Click Finish
The Apk is generated but it's not signed! What is the problem ?
Here is my app build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 27
defaultConfig {
applicationId "com.twobreathe.soft2breathe"
minSdkVersion 23
targetSdkVersion 27
versionCode 9
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
vectorDrawables {
useSupportLibrary true
}
resConfigs "en", "ja"
}
signingConfigs {
release {
keyAlias "[my key alias]"
keyPassword "[my key password]"
storeFile file("[path to the keystore file]")
storePassword "[my store password]"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
pseudoLocalesEnabled false
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/fluidsynth/android/CMakeLists.txt"
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
dataBinding {
enabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '28.0.3'
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.18.4'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.orhanobut:hawk:2.0.1'
implementation 'xyz.sahildave:arclayout:1.0.0'
implementation 'com.mikhaellopez:circularprogressbar:2.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation 'com.github.GrenderG:Toasty:1.3.0'
implementation 'com.kyleduo.switchbutton:library:2.0.0'
implementation 'com.github.franmontiel:LocaleChanger:0.9.2'
implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
}
After updating to 3.3, many problems are occuring related to signing an APK. Sometime it doesn't sign the apk and sometime it says the key is not private.
Well i also faced this problem after upgrading to android studio 3.3 and i resolved in 3 steps. But firstly make sure you backup your whole project.
In Android Studio goto File > Project Structure and untick from "use embedded JDK" then click OK
Goto Computer Settings (system settings) (win + pause key) then go to Advanced system settings>Environment variables. if JAVA_HOME not present then add it and set path to your installed JDK.
As i couldn't find a direct approach to modify jdk path in my project that is upgraded in some way to android studio 3.3 settings, i did following(for the last step) BUT MAKE SURE YOU MAKE BACKUP BEFORE THIS.
To make sure where i am guiding come to project view, I deleted ".grade", ".idea", "capture", "gradle" folders from the root and "build", "release", "lib" folder from "app" leaving "src" as it is. Deleted root.iml and did not delete app.iml file Then rebuild the project and then created the Signed package.
It went successful after 2 try. To be very honest i did the last step twice by restoring files from backup. As deleting these folders i messed up 1 time.
Not strictly related, but I ended up in this questions when searching for a fix to my problem.
In my case I forgot to remove 'debuggable true' for one of my non-debug built-types. When I was generating the bundle the google play store wouldn't complain about it just said that it wasn't signed. But when I tried uploading an apk it showed the true error.
From your Gradle its visible that you have not configured your Signing Config with it.
Please check image below:
Step 1:
Go to your project settings > select your module (Let's say "app") > go to signing > enter proper information and keystore.jks file
Step 2:
Go to Build Types > select Release type > assign signing config as you created on step 1. > after that your gradle will have config as there in image.
Step 3:
Try generating signed APK.
It will be success!!!
Happy Coding..
Double check both of the values on the final dialog, labelled by "Signature Versions".
For more information please check the following link:
https://developer.android.com/about/versions/nougat/android-7.0#apk_signature_v2
Anyway this question seems duplicate as the following:
android studio: release apk is not signed
friend
when you go for build the signed apk
now in android studio 3.3 , you will 2 option for build the signed apk.
1. Android App Bundle
2.APK
i will suggest to use option 2
select option 2 and Click on Next button now studio ask for your password details
now fill all details and
select Remember password checkbox for feature and now next .
now again studio ask for debug and release build confirmation
now here select release and select 2 checkbox at bottom and then continue
hope your signed apk will be generate .
When generating an APK, make sure both the signature types are checked, otherwise Fabric (and other places) may not recognise it as signed.
Additionally you probably want to remove debuggable true from your release config, as debuggable builds can't be uploaded to Google Play. There's a chance this is also causing an issue.
Try to sign it using command-line tools. I may help you to identify the problem.
(https://developer.android.com/studio/build/building-cmdline).
In my case, it was JAVA_HOME problem (as in #Vanshaj Daga answer).
What I want to do & the problem
I updated my Android Studio and Android Gradle Plugin to 3.0.1 and my Gradle Wrapper to 4.1 and can build & deploy my Android Gradle project in release variant on a device via IDE.
However, the following 'Gradle Sync' warning messages are shown:
Warning:Module 'library' has variant 'release' selected, but the modules ['integration-test'] depend on variant 'debug'
The problem here is, that there is no 'release' variant for the integration-test module which uses the 'com.android.test'
plugin.
If I simply try to add a release build type (buildTypes { release {} }) to the :integration-test module I receive:
Error:VariantInputs initialized with no merged manifest report on: DEFAULT
Details about the project (simplified)
The project consists of:
a :library module
an :app module which builds the app's apk and uses the :library module
an :integration-test module which:
uses the "com.android.test" plugin
dependents on the :app module via targetProjectPath ':app' & targetVariant 'debug'
and contains instrumented tests on the :app functions
only contains a 'main' folder (the test plugin does not support others)
This project is build after the Android Test Blueprint as the goal is here that the :app module does not know anything about the integration-test module's existence.
settings.gradle
include :library
include :app
include :integration-test
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
publishNonDefault true
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationId "xxxxx"
testInstrumentationRunner rootProject.ext.testInstrumentationRunner
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
release {
keyAlias 'xxxx'
}
}
buildTypes {
debug {
testCoverageEnabled = true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
// This is needed by the integration-test module (i.e. com.android.test : integration test)
// in order for targetVariant to work without a flavor
publishNonDefault true
testOptions {
unitTests {
// Required so that logging methods do not throw not mocked exceptions in junit tests.
returnDefaultValues = true
}
}
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibility
targetCompatibility rootProject.ext.targetCompatibility
}
}
dependencies {
// Local dependencies
compile project(':library')
// i cleaned up all the other dependencies as they wouldn't help here
}
Question
Did anyone get an (integration-)test module using the com.android.test plugin to run with Android Gradle Plugin 3.0.1 without getting the "no release variant" error? If so, how can I avoid this error or how can I add such a release variant to a android test plugin based module (if this makes sense at all)?
I was also getting
VariantInputs initialized with no merged manifest report on: DEFAULT.
Then I followed exactly what is outlined in the https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint
The error went away when I removed release buildType from the `buildTypes' block in the test module's Gradle file.
From this:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
to
buildTypes {
}
It’s been some time now that Instant Run is not working anymore, that is, it’s slower than standard builds.
There’s some material in the AOSP bug tracker, but I could not work this out. I’m sure some of you will help.
Without Instant Run
Builds take about 1.30 min.
With Instant Run
I run the app for the first time, then apply some minor change. For example, change int a = 1 to int a = 2 inside a method, or alter a string.
Then click run again. What happens:
A seemingly full build takes place (calling assembleDebug on all my modules). Takes about 1.30 min.
A second round goes on, calling just app:assembleDebug. It takes about another minute:
16:27:10 Executing tasks: [:app:assembleDebug]
16:28:16 Gradle build finished in 1m 5s 264ms
16:28:22 Instant Run applied code changes and restarted the app.
During the first round, no output whatsoever to Event Log or Gradle Console. During second round, the Gradle Console outputs lots of stuff and ends with
BUILD SUCCESSFUL
Total time: 51.385 secs
PREDEX CACHE HITS: 0
PREDEX CACHE MISSES: 45
Stopped 0 compiler daemon(s).
What can I do?
I have these in my grade.properties file:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
Nothing dex related in build.gradle files. Not using Jack. Android Studio 2.2.3.
gradle.properties file
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
ANDROID_BUILD_MIN_SDK_VERSION=15
ANDROID_BUILD_TARGET_SDK_VERSION=25
ANDROID_BUILD_SDK_VERSION=25
ANDROID_BUILD_TOOLS_VERSION=25.0.2
Project level build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Main module build.gradle
(I have other two ‘library’ modules also)
apply plugin: 'com.android.application'
Properties signProp = new Properties()
signProp.load(new FileInputStream(file(project.property("SIGN_PROPS"))))
Properties authProp = new Properties()
authProp.load(new FileInputStream(file(project.property("AUTH_KEYS_PROPS"))))
def PARSE_APPLICATION_ID = '"' + authProp['parseApplicationId'] + '"';
def PARSE_CLIENT_KEY = '"' + authProp['parseClientKey'] + '"'
def PARSE_SERVER_URL = '"' + authProp['parseServerURL'] + '"'
def GOOGLE_PLAY_API_KEY = '"' + authProp['googlePlayApiKey'] + '"'
android {
signingConfigs {
release_config {
keyAlias signProp['keyAlias']
keyPassword signProp['keyPassword']
storeFile file(signProp['storeFilePath'])
storePassword signProp['storePassword']
}
}
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode 21
versionName "1.3.3"
buildConfigField 'String', 'PARSE_APPLICATION_ID', PARSE_APPLICATION_ID
buildConfigField 'String', 'PARSE_CLIENT_KEY', PARSE_CLIENT_KEY
buildConfigField 'String', 'PARSE_SERVER_URL', PARSE_SERVER_URL
buildConfigField 'String', 'GOOGLE_PLAY_API_KEY', GOOGLE_PLAY_API_KEY
signingConfig signingConfigs.release_config
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
debug {
minifyEnabled false
shrinkResources false
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:preference-v14:24.2.1'
compile 'com.google.maps.android:android-maps-utils:0.4.3'
compile 'com.google.android.gms:play-services-maps:9.2.1'
compile 'com.google.android.gms:play-services-appinvite:9.2.1'
compile 'com.google.android.gms:play-services-location:9.2.1'
compile 'com.google.android.gms:play-services-appindexing:9.2.1'
compile ('com.facebook.android:facebook-android-sdk:4.16.1') {
exclude module: 'bolts-tasks'
}
compile 'com.parse.bolts:bolts-tasks:1.4.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.parse:parse-android:1.13.1'
compile ('com.parse:parseui-widget-android:0.0.1') {
exclude module: 'parse-android'
}
compile project(':dateTimePicker')
compile project(':commons')
}
apply plugin: 'com.google.gms.google-services'
http://tools.android.com/recent/androidstudio223isnowavailable
Update to the latest version of Android Studio and then increase the memory profile in (studio.vmoptions) based on your system memory
-Xms256m
-Xmx1280m
-XX:MaxPermSize=350m
Enable Instant Run
Open the Settings or Preferences dialog.
Navigate to Build, Execution, Deployment > Instant Run.
check the box next to Enable Instant Run.
Limitations of Instant Run.
Deploying to multiple devices,
Multidexing your app,
Using third-party plugins,
Pushing changes to multi-process apps,
Launching your app in a Work profile.
If you use multidex support (multiDexEnabled true) for your app, minSdkVersion must be 21 or higher. Otherwise, android studio disables Instant Run.
Android plugin for gradle version must be 2.1.0 or higher
Enable Offline Work android studio to speed up:
Go to file >> settings or simply press ctrl + alt + s
file >> settings >> Gradle. please check Offline work under Global Gradle setting
Improve Gradle Performance
After opening android studio, open gradle.properties file from right side of android studio and add the following two lines.
org.gradle.jvmargs=-Xmx1536m
org.gradle.daemon=true
org.gradle.parallel=true
Configure Build Variants of debug in buildTypes
debug {
minifyEnabled false
applicationIdSuffix ".debug"
}
After changes, you should restart your Android Studio.
Note: Build time depend on your processor and RAM.
I noticed in (i7-3610qm with 8gb ram) when you compile 4 android studio project at same time then slow respond on window. after build process finish pc works normal.
Maintain bulit versions and target version as same
Environment:
Mac OS 10.10.3
Android studio:1.2.11
grandle:2.2.1
the log:
Information:Gradle tasks [:generateDebugSources, :generateDebugTestSources]
:preBuild
:preDebugBuild
:checkDebugManifest
:prepareDebugDependencies
:compileDebugAidl FAILED
Error:Execution failed for task ':compileDebugAidl'.
> aidl is missing
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
String SDK_DIR = System.getenv("ANDROID_HOME")
if(SDK_DIR == null) {
Properties props = new Properties()
props.load(new FileInputStream(project.rootProject.file("local.properties")))
SDK_DIR = props.get('sdk.dir');
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
proguardFiles 'proguard.cfg'
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
provided files("${SDK_DIR}/platforms/android-17/data/layoutlib.jar")
//compile files('libs/pass-v1.1.3.jar')
// compile files('libs/sdk-v1.0.0.jar')
}
before this, I had compile the android resource 4.4 on my Mac, and modified some files in OS system, I think it is the reason is that, but I've forget which file, Someone encountered this problem yet
In my case I downloaded version 22 of Android M and Android 5.1.1 using Android Studio 1.2.1.1 but when I try to do a Hello World this same error showed me
So the solution was go to do right click in app like the image below and choose "Open Module Settings".....
then there you have 2 options. I've changed both with the last version I had.
Compile SDK version to API 21 Lollipop
and Build Tools Version to 21.1.2
Finally clean the project and Build
UPDATE
Here is my build.gradle to compare with your build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.android.bmi"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
UPDATED
TO Get Android Studio 1.3 follow this steps
Open the Settings window by choosing File > Settings.
Choose the Appearance & Behavior > System Settings > Updates panel.
On the Updates panel, choose the option Automatically check updates for: Canary Chanel.
On the Updates panel, select Check Now to check for the latest canary build. 5. Download and install the build when you are prompted.
Then you'll have something like this to update your Android Studio to 1.3 and with this you can test Android M
I solve my issue, set the build tools version from 21.1.2 to 22.0.1, hope it can help who meet the same.
For those you are still getting the "aidl is missing" error:
To me, setting back the build tools version is not a solution at all.
On your top level build.gradle file, try setting:
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.3.1'
and then use buildToolsVersion '23.0.1'.
It worked perfectly for me. I hope it helps others.
Following the screen shots from Jorge's post all you have to do is make sure you do not select Build Tools Version 23.0.0 rc1. I have not fully investigated that version in the IDE or on Google's bug tracker but all I had to do was pick the previous tool version and it worked just fine after doing a clean build. I tried this out with various SDK min versions.
I am running OSX 10.10.3 with Android Studio 1.2.1.1 running on Oracle JDK 1.8.0_45-b14
UPDATED WITH SOLUTION
This issue is identical in nature to Execution failed for task ':app:compileDebugAidl': aidl is missing. Please read my post for the proper solution and references to the genesis of the solution.
people who are building apps with android studio 1.3 preview might get Debug AIDL missing error
Solution:(Follow in sequence)
1) Download all the tools under preview channel (i.e. revision no 23.0.0 rc1)
2) Download play servies and android support repo support under extras
3)Restart Android Studio
4)Press F4 and set compile SDK version to API 22+ and Build tool version 23.0.0 rc1
5)open build.gradle(Project:******) and change classpath line with classpath 'com.android.tools.build:gradle:1.3.+'
I followed screenshots from Jorge's post. But did not have API 21 as an option. So I kept Compiled SDK Version 'API 22: Android 5.1 (Lollipop)' as it is and changed Build Tool Version from 23.0.0 rc1 to 22.0.1
I also had to install JDK 7 since 22.0.1 did not support JDK 6. After that gradle build succeded.
In my experience, there is not about Compile Sdk Version or Build Tool Version, is about the New Project Structure. According to this issue, Aidl files are supposed to be in src/main/aidl, once you put *.aidl at the supposed directory, Android Studio would serve it as expect.
And If you want to have them in src/main/java, then you need the remapping instruction as you've specified, like below :
sourceSets {
main {
aidl.srcDirs = ['src/main/java']
}
}
btw, in my situation, the remapping approach work only by Gradle 2.4(also probably above version).
I started using Gradle build system a few days ago and got the script to work as I wanted, here it is:
buildscript {
repositories {
mavenCentral()
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion '18.0.1'
productFlavors {
flavor1 {
packageName "flavor1"
}
flavor2 {
packageName "flavor2"
}
flavor3 {
packageName "flavor3"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
signingConfigs {
release {
storeFile file("test.keystore")
storePassword "*****"
keyAlias "****"
keyPassword "*****"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
}
As you can see there is nothing fancy here just building 3 flavours of the app and signing them with the same key. I just run gradle assembleRelease and after 20 seconds I have my apks in build folder. But the problem is that there are other files generated that I don't want for example appname-release-unaligned.apk.
I know that this file is needed before apk can be signed but would like to add a task to delete these files in my gradle script?
Also if it's possible I would like to remove all other (shell I say artefact files) generated during build. Essentially I would like to run something like gradle clean but leave the build apk files. How do I do this?
BONUS:If anyone has pointers on how can I optimise this script and enable zip align and proguard (without custom rules just default obfuscation is ok) that would also help me since I am very new to gradle and none of the tutorials I followed explains these steps.
UPDATE February 2018.
This block will cause a build error using Android Gradle plugin 3.0 or above. See 'deepSymmetry's comment below.
The "fix" is to delete the block altogether and the plugin's default behavior will automatically clean up the intermediate temporary apks (ex: app-debug-unaligned.apk).
Pretty old topic but here is modern solution for deleting unnecessary 'unaligned' file. This is quite handy especially on CI servers to save some space.
That's a shame that plugin does not provide hook for 'zipAlign' task so we'll need to hook on 'assemble' task which goes after 'zipAlign'.
Works with last gradle plugin 1.2.0 (gradle-2.4) but should be valid for 1.+
// delete unaligned files
android.applicationVariants.all { variant ->
variant.assemble.doLast {
variant.outputs.each { output ->
println "aligned " + output.outputFile
println "unaligned " + output.packageApplication.outputFile
File unaligned = output.packageApplication.outputFile;
File aligned = output.outputFile
if (!unaligned.getName().equalsIgnoreCase(aligned.getName())) {
println "deleting " + unaligned.getName()
unaligned.delete()
}
}
}
}
And another one if your prefer to check zipAlignEnable flag but in this case you'll be tied to "unaligned" constant in filename because release builds with zipAlignEnabled=true AND without signingConfig skip 'zipAlign' task and produce only one file: 'app-release-unsigned.apk'.
// delete unaligned files
android.applicationVariants.all { variant ->
variant.assemble.doLast {
variant.outputs.each { output ->
println "aligned " + output.outputFile
println "unaligned " + output.packageApplication.outputFile
File file = output.packageApplication.outputFile;
if (variant.buildType.zipAlignEnabled && file.getName().contains("unaligned")) {
println "deleting " + file.getName()
file.delete()
}
}
}
}
I am using the first one in case anyone cares.
I noticed there is some activity on this question from time to time so here is the way I solved the problem if it helps someone. Just define new task to copy file and then set execution order.
task copyTask(type: Copy) {
from 'build/apk'
into 'apks'
exclude '**/*-unaligned.apk'
}
task allTask(dependsOn: ['clean', 'assembleRelease', 'copyTask']){
clean.mustRunAfter copyTask
copyTask.mustRunAfter assembleRelease
}
then just call this allTask when you want to do a build.
I can at least answer your bonus-question:
buildTypes {
release {
runProguard true
signingConfig signingConfigs.release
}
}
If you have specific proguard-rules, just enter this line to your defaultConfig or to your product flavors:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
The first proguard rule is the generla one from your Android SDK, the second one is from your module-directory.
ZipAlign is enabled by default if you build you project with the build variant release.
Just a little bit modified answer from #PSIXO, сonsidering Android Studio 1.5, running test cases and renaming apk file for better CI integration:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.mydemoci"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
archivesBaseName = "$applicationId-v$versionName"
}
}
task copyOutputApk(type: Copy) {
from 'build/outputs/apk'
into 'apk'
exclude '**/*-unaligned.apk'
}
task buildTestDebug(dependsOn: ['clean', 'assembleDebug', 'check', 'copyOutputApk']) {
check.mustRunAfter assembleDebug
copyOutputApk.mustRunAfter check
clean.mustRunAfter copyOutputApk
}
To start build run gradlew buildTestDebug