Run task once at the end in gradle - android

I need some task what will run at the end. Lets say some println. I seen multiple examples of how to run task at the end and they always depend on other task, so I don't really get how to do it and I don't have tasks. For now I have some piece of code:
if (releaseBol)
{
// Some of my code
// Run twice, one for lab and other for prod
println fileName
}
That piece of code run twice, once for lab flavor and one for prod flavor in case I run:
MyApp:assembleRelease -PRELEASE=1
I need this peace of code to run only once, so for that I need to run it once at the end.
My full gradle:
import org.tmatesoft.svn.core.wc.*
apply plugin: 'com.android.application'
def BuildNumberFile = new File('./BuildNumber.txt')
def BuildNumber = 'BRND'
def _versionName = '1.0.1'
def _applicationId = 'com.myapp.android.pic'
def _versionCode = 17
def fileName = ''
def obfuscated = false
def releaseBol = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
lintOptions {
abortOnError false
}
def lines = BuildNumberFile.readLines()
BuildNumber = 'S'+lines.get(0)
defaultConfig {
applicationId _applicationId
minSdkVersion 15
targetSdkVersion 23
versionCode _versionCode
versionName _versionName
multiDexEnabled true
resValue 'string', 'BUILD_NUMBER_RES', BuildNumber
}
if (project.hasProperty('RELEASE') && project.ext.RELEASE == '1')
releaseBol = true
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}." + BuildNumber + "-" + getSvnRevision() + ".apk"))
fileName=output.outputFile.name
}
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()
}
}
if (releaseBol) {
// Some of my code
// Run twice, one for lab and other for prod
println fileName
}
}
}
signingConfigs {
release {
storeFile file('myapp')
storePassword "myapp123"
keyAlias 'myapp'
keyPassword "myappmobile"
}
}
productFlavors {
prod {
}
lab {
}
}
buildTypes {
release {
minifyEnabled obfuscated
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'
signingConfig signingConfigs.release
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
jumboMode true
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':trunk')
}
It just help me if you can add some println to this gradle that will run once at the end.

You need to add an instance of BuildListener:
class BA extends BuildAdapter {
void buildFinished(BuildResult result) {
println "finished"
}
}
gradle.addListener(new BA())
EDIT
When it comes to releaseBol it can be done in the following way:
project.ext.releaseBol = false
class BA extends BuildAdapter {
Project project
BA(Project project) {
this.project = project
}
void buildFinished(BuildResult result) {
println "finished $project.releaseBol"
}
}
gradle.addListener(new BA(project))
EDIT 2
You can also utilize gradle's TaskExecutionGraph. With whenReady closure you can get info that the graph is ready and filled with tasks. At this time there's no option to modify the graph (add/remove task, change order) but you can (via getAllTasks) get the last one and... add an action. Here's how it looks like:
task someTask << {
println "run"
}
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks[-1] << {
println 'finished'
}
}

Related

why change default app name did not work in android productFlavors build with flutter

Now I am using android productFlavors to package app in flutter, this is my command:
~/apps/flutter/bin/flutter build apk --release --flavor prod -t lib/main_pro.dart --no-sound-null-safety
but the output name is always app-prod-release.apk:
$ ~/apps/flutter/bin/flutter build apk --release --flavor prod -t lib/main_pro.dart --no-sound-null-safety ‹ruby-2.7.2›
Changing current working directory to: /Users/dolphin/source/cruise-open
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Running Gradle task 'assembleProdRelease'...
Running Gradle task 'assembleProdRelease'... Done 7.1s
✓ Built build/app/outputs/flutter-apk/app-prod-release.apk (23.7MB).
(base)
this is my android/app/build.gradle gradle config:
flavorDimensions 'app'
productFlavors {
prod {
dimension 'app'
resValue "string", "app_name", "Cruise"
manifestPlaceholders = [
"APP_NAME" : "cruise-production"
]
}
}
now I want the package name likecruise-prouction-release.apk, not app-prod-release.apk. what should I do to change the defualt package name? I have tries this to change the output package name to releaseApkName.apk:
buildTypes {
release {
signingConfig signingConfigs.debug
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
println("releaseApkName")
output.outputFileName = "releaseApkName.apk"
}
}
}
}
but it seems not worked. This is my full config now:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.earth.dolphin"
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig signingConfigs.debug
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "a.apk"
}
}
}
}
flavorDimensions 'app'
productFlavors {
dev {
dimension 'app'
resValue "string", "app_name", "Cruise-dev"
applicationIdSuffix '.dev'
}
stage {
dimension 'app'
resValue "string", "app_name", "Cruise-stage"
applicationIdSuffix '.stage'
}
prod {
dimension 'app'
resValue "string", "app_name", "Cruise"
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
the gradle version is 5.6.2. This is the output still using default name:
finally I am using this script, it works:
buildTypes {
release {
signingConfig signingConfigs.debug
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def buildType = variant.buildType.name
println("buildType=" + buildType)
if (buildType != "debug") {
def projectRootDir = "$rootDir"
def outputFileDir = new File(projectRootDir + File.separator, "apk")
println("outputFileDir=" + outputFileDir)
def productFlavorsName = productFlavors.name.toString()
def oldApkFlavorsName = productFlavorsName.replace("[", "").trim()
def newApkFlavorsName = oldApkFlavorsName.replace("]", "").trim()
println("newApkFlavorsName=" + newApkFlavorsName)
def apkFlavorsNameDir = new File(outputFileDir, newApkFlavorsName)
println("apkFlavorsNameDir=" + apkFlavorsNameDir)
// variant.getPackageApplicationProvider().get().outputDirectory = apkFlavorsNameDir
def appName
if (productFlavorsName.contains("dev")) {
appName = "cruise-dev"
} else if (productFlavorsName.contains("test")) {
appName = "cruise-beta"
} else if (productFlavorsName.contains("prod")) {
appName = "cruise-release"
}else{
appName = "cruise-beta"
}
def releaseApkName = "" + appName + "-" + defaultConfig.versionName + ".apk"
output.outputFileName = releaseApkName
}
}
}
}
}
the package output path is:
/Users/dolphin/source/cruise-open/build/app/outputs/apk/prod/release
look like this:

Proguard error while signing APK with Android Studio

I am trying to debug my error with Proguard. My project is working fine with debug but not with Proguard. Any help will be appreciated.
I have tried with ignore warning in Proguard. However application is crashing with generated APK.
Current Proguard settings is not working. Messages console I have uploaded to Gist
Build.gradle is given below
Prodguard-project.txt in gist
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
build.gradle
apply plugin: 'com.android.application'
apply from: rootProject.file('gradle/codequality.gradle')
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
versionCode 49
versionName "1.8.8"
minSdkVersion 14
targetSdkVersion 22
buildConfigField 'String', 'BUILD_TAG', '"' + getBuildTag() + '"'
buildConfigField 'String', 'OWM_API_KEY', '"' + getOpenWeatherMapApiKey() + '"'
buildConfigField 'boolean', 'ENABLE_WEATHER', 'true'
def buildSuffix = getBuildSuffix(versionName, versionCode)
applicationVariants.all { variant ->
def file = variant.outputs[0].outputFile
variant.outputs[0].outputFile = new File(file.parent, file.name.replace(".apk", "-" + buildSuffix + ".apk"))
}
}
if (project.hasProperty('signingKeyStoreFile')) {
signingConfigs {
release {
storeFile file(signingKeyStoreFile)
storePassword signingKeyStorePassword
keyAlias signingKeyAlias
keyPassword signingKeyPassword
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFile 'proguard-project.txt'
if (project.hasProperty('signingKeyStoreFile')) {
signingConfig signingConfigs.release
}
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
disable 'MissingTranslation'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
def getBuildSuffix(versionName, versionCode) {
def suffix = versionName + '-' + versionCode
if (System.getenv()['BUILD_NUMBER'] != null) {
suffix += '-b' + System.getenv()['BUILD_NUMBER']
}
return suffix
}
def getBuildTag() {
def tag = ''
if (System.getenv()['BUILD_NUMBER'] != null) {
tag += 'b' + System.getenv()['BUILD_NUMBER']
} else {
tag += 'l'
}
tag += '#' + new Date().format('yyyyMMdd')
return tag
}
def getOpenWeatherMapApiKey() {
if (project.hasProperty('owmApiKey')) {
return owmApiKey
} else {
def apiKeyFile = file('default_owm_api_key');
if (apiKeyFile.isFile()) {
return apiKeyFile.text.trim()
}
}
return 'NOKEY'
}
///////////////////////////////////////////////////
// Dependencies
repositories {
mavenCentral()
}
dependencies {
//compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
//compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'net.danlew:android.joda:2.9.4.1'
compile 'com.google.android.gms:play-services-ads:9.8.0'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
}
configurations {
all*.exclude group: 'com.google.firebase', module: 'firebase-core'
all*.exclude group: 'com.google.firebase', module: 'firebase-iid'
}
///////////////////////////////////////////////////
// Checkstyle
task checkstyleDebug(type: Checkstyle, dependsOn: 'compileDebugSources') {
source = fileTree('src/main/java/')
classpath = files('build/intermediates/classes/debug')
}
check.dependsOn checkstyleDebug
///////////////////////////////////////////////////
// Findbugs
task findbugsDebug(type: FindBugs, dependsOn: 'compileDebugSources') {
source = fileTree('src/main/java/')
classes = fileTree('build/intermediates/classes/debug')
classpath = files() // empty classpath!
effort = 'max'
excludeFilter = rootProject.file('config/findbugs/androidExcludeFilter.xml')
}
check.dependsOn findbugsDebug
///////////////////////////////////////////////////
// PMD
task pmd(type: Pmd) {
source = fileTree('src/main/java/')
ruleSets = ['java-basic', 'java-braces', 'java-android']
}
check.dependsOn 'pmd'
Try to add getDefaultProguardFile('proguard-android.txt') to the proguardFile 'proguard-project.txt', to get next row:
proguardFile getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
Or start to search the issues from your proguard-project.txt, like:
Add rule -keepattributes SourceFile,LineNumberTable,InnerClasses,Signature,Exceptions
Add rule -dontwarn com.google.**
And so on, by your proguard failed logs

Auto increment version code on Generate signed APK only

I have successfully incremented version code. But I only want to increment it while I do generate signed apk from menu Build -> Generate signed APK. Following is my gradle code.
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['build.version'].toInteger() + 1
versionProps['build.version']=code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
applicationId "com.test"
multiDexEnabled true
versionCode code
versionName "1.1"
minSdkVersion 18
targetSdkVersion 23
}
}
else {
throw new GradleException("Could not read version.properties!")
}
buildTypes {
release {
//minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
preDexLibraries = false
}}
And my version.properties file contains following info:
Minor=7
Branch=4
Major=10
build.version=73
I am able to do it by hooking up my code on assembleRelease gradle task. Got help from Tim's blog. Following is the code-
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
def Properties versionProps = loadVersionFile()
defaultConfig {
applicationId "com.test"
multiDexEnabled true
versionCode getCode(versionProps)
versionName getName(versionProps)
minSdkVersion 18
targetSdkVersion 23
}
signingConfigs {
release {
storeFile file(".../keys.jks")
storePassword "..."
keyAlias "..."
keyPassword "..."
}
}
buildTypes {
release {
signingConfig signingConfigs.release
//minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
}
dexOptions {
...
}
}
def loadVersionFile() {
def versionPropsFile = file('version.properties')
def Properties versionProps
if (versionPropsFile.canRead()) {
versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
} else {
throw new GradleException("Could not read version.properties!")
}
return versionProps}
def getCode(Properties versionProps) {
return versionProps['build.version'].toInteger()}
def getName(Properties versionProps) {
return versionProps['product.version']}
assembleRelease << {
def versionPropsFile = file('version.properties')
def code
def Properties versionProps
if (versionPropsFile.canRead()) {
versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
code = versionProps['build.version'].toInteger() + 1
} else {
throw new GradleException("Could not read version.properties!")
}
versionProps['build.version'] = code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
project.android.defaultConfig.versionCode code}
allprojects {
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'libs'
}
maven {
...
}
}}
dependencies {...}
apply plugin: 'com.google.gms.google-services'
To find out where you have to place the gradle.properties
Extract the whole signing config
First option is, to extract the whole signing config to a separate user file. Create a new property in your gradle.properties:
MyProject.signing=/home/username/.signing/myproject
MyProject doesn’t need to match any application names or so, you can in fact name the property whatever you like. Also if you’re on windows use \ instead of /.
Place your keystore at /home/username/.signing/myproject.keystore.
Now create a file name myproject.gradle in /home/username/.signing (create the folder if necessary). This file will contain your signing config, that should be used to sign the package. This could look like the following:
android {
signingConfigs {
release {
storeFile file(project.property("MyProject.signing") + ".keystore")
storePassword "mypassword"
keyAlias "KeyAlias"
keyPassword "mypassword"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
Now its time to configure the actual build.gradle file in the project you want to use this signing config. Just add the following lines to it:
if(project.hasProperty("MyProject.signing")
&& new File(project.property("MyProject.signing") + ".gradle").exists()) {
apply from: project.property("MyProject.signing") + ".gradle";
}
Only extract some variables from file
project.ext {
uploadRepo = 'http://....'
uploadUser = 'myusername'
uploadPass = 'mypass'
}
Now make sure you only use the variables if they are available by putting the configuration in the if after you loaded the file. So your build.gradle could look like that:
if(project.hasProperty("MyProject.signing")
&& new File(project.property("MyProject.signing") + ".gradle").exists()) {
apply from: project.property("MyProject.signing") + ".gradle";
// Configure stuff that relies on these variables
uploadArchives {
repositories.mavenDeployer {
repository(url: uploadRepo) {
authentication(userName: uploadUser, password: uploadPass)
}
}
// .. whatever else you need ...
}
}
Only extract some strings from file
Again add a path to your gradle.properties (let’s do it a full path this time):
MyProject.properties=/home/username/.signing/myproject.properties
if(project.hasProperty("MyProject.properties")
&& new File(project.property("MyProject.properties")).exists()) {
Properties props = new Properties()
props.load(new FileInputStream(file(project.property("MyProject.properties"))))
android {
signingConfigs {
release {
storeFile file(props['keystore'])
storePassword props['keystore.password']
// ...
}
}
}
}
Just generate a plain properties file at /home/username/.signing/myproject.properties:
keystore=/path/to/my/keystore
keystore.password=mypassword

How to include additional configuration file inside build.gradle file

Is there any ability to include file inside build.gradle file?
I want to separate same configurations from few projects into one file and than just include it inside build.gradle.
For example, now I have file like this:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 15
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 15
targetSdkVersion 22
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
println outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def manifestParser = new com.android.builder.core.DefaultManifestParser()
def version = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
def fileName = outputFile.name.replace('.apk', "-${version}.apk")
println fileName
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
lintOptions {
abortOnError false
}
//Signing app
if(project.hasProperty("debugSigningPropertiesPath") && project.hasProperty("releaseSigningPropertiesPath")) {
File debugPropsFile = new File(System.getenv('HOME') + "/" + project.property("debugSigningPropertiesPath"))
File releasePropsFile = new File(System.getenv('HOME') + "/" + project.property("releaseSigningPropertiesPath"))
if(debugPropsFile.exists() && releasePropsFile.exists()) {
Properties debugProps = new Properties()
debugProps.load(new FileInputStream(debugPropsFile))
Properties releaseProps = new Properties()
releaseProps.load(new FileInputStream(releasePropsFile))
signingConfigs {
debug {
storeFile file(debugPropsFile.getParent() + "/" + debugProps['keystore'])
storePassword debugProps['keystore.password']
keyAlias debugProps['keyAlias']
keyPassword debugProps['keyPassword']
}
release {
storeFile file(releasePropsFile.getParent() + "/" + releaseProps['keystore'])
storePassword releaseProps['keystore.password']
keyAlias releaseProps['keyAlias']
keyPassword releaseProps['keyPassword']
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
}
}
}
}
And I want to simplify it something like this
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 15
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 15
targetSdkVersion 22
}
include 'applicationVariants.gradle'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
lintOptions {
abortOnError false
}
include 'signing.gradle'
}
You can include an an external build script. Check the official guide:
Just use:
apply from: 'signing.gradle'
i have done some thing like this.
in my libraries.gradle
ext {
//Android
targetSdkVersion = 22;
compileSdkVersion = 22;
buildToolsVersion = '22.0.1'
....
dagger2Version = '2.0'
butterknifeVersion = '6.1.0'
appCompatVersion = '22.2.0'
designVersion = '22.2.0'
recyclerViewVersion = '22.2.0'=
libraries = [
supportAnnotations: "com.android.support:support-annotations:${androidSupportAnnotationsVersion}",
googlePlayServices: "com.google.android.gms:play-services:${googlePlayServicesVersion}",
recyclerView : "com.android.support:recyclerview-v7:${recyclerViewVersion}",
picasso : "com.squareup.picasso:picasso:${picassoVersion}",
cardView : "com.android.support:cardview-v7:${cardViewVersion}",
appCompat : "com.android.support:appcompat-v7:${appCompatVersion}",
design : "com.android.support:design:${designVersion}",
findBugs : "com.google.code.findbugs:jsr305:${findbugsVersion}",
gson : "com.google.code.gson:gson:${gsonVersion}",
flow : "com.squareup.flow:flow:${flowVersion}",
butterknife : "com.jakewharton:butterknife:${butterknifeVersion}",
rxjava : "io.reactivex:rxjava:${rxjavaVersion}",
rxandroid : "io.reactivex:rxandroid:${rxandroidVersion}",
androidSupport : "com.android.support:support-v13:${androidSupportVersion}",
androidSupportV4: "com.android.support:support-v4:${androidSupportVersion}",
javaxInject : "javax.inject:javax.inject:${javaxInjectVersion}",
retrofit : "com.squareup.retrofit:retrofit:${retrofitVersion}",codec:${commonsCodecVersion}","com.facebook.stetho:stetho:${stethoVersion}",
apache : "org.apache.commons:commons-lang3:${apacheVersion}",
libPhoneNumber : "com.googlecode.libphonenumber:libphonenumber:$libPhoneNumber",
dagger2 : "com.google.dagger:dagger:${dagger2Version}",
dagger2Compiler : "com.google.dagger:dagger-compiler:${dagger2Version}",
javaxAnnotations : "javax.annotation:javax.annotation-api:${javaxAnnotationVersion}"
]
}
in my app.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':logic')
compile project(':local-resources')
compile project(':api')
compile rootProject.ext.libraries.appCompat
compile libraries.design
compile rootProject.ext.libraries.recyclerView
compile rootProject.ext.libraries.butterknife
compile rootProject.ext.libraries.dagger2
compile libraries.rxandroid
compile libraries.stetho
compile libraries.cardView
compile libraries.picasso
apt rootProject.ext.libraries.dagger2Compiler
or apply from: rootProject.file('checkstyle.gradle')

Building a debug APK

I'm having trouble with building a debuggable apk. I'm using Android Studio 0.5.4/0.5.5 and Gradle 1.11 Gradle plugin 0.9.+ and somehow the debug apk doesn't show any logcat messages with the package name anymore. I tried many different things uninstall everything Android studio/AndroidSDK. and clean installing it again, also deleted all home folder .gradle .androidstudiopreview and nothing helped. When I created a new project in android studio and follow the wizard for creating an activity everything seems fine the app is debuggable and shows normal logging output in logcat. Also when I want to selected the process for debug, Android Studio can't find it as a debuggable process. Anyone know how to fix this or what is wrong in my build.gradle file
the output from log messages is like this now:
04-15 14:09:11.066 21202-21202/? D/Tag﹕ test tag and debug messages
04-15 14:09:11.066 21202-21202/? I/Tag﹕ test tag and info messages
04-15 14:09:11.066 21202-21202/? W/Tag﹕ test tag and warn messages
04-15 14:09:11.066 21202-21202/? E/Tag﹕ test tag and error messages
04-15 14:09:11.076 21202-21202/? D/Tag﹕ is debuggable: true
build.gradle:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
def gitSha() {
return 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
}
def buildTime() {
return new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
}
def isTravis = "true".equals(System.getenv("TRAVIS"))
def preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
android {
final GITSHA = "${gitSha()}";
final BUILD_TIME = "${buildTime()}";
final YOUTUBE_DEV_API = "AIzaSyD0kNRnV_Il6bYx5ekWUzPWNt9XDQIPxvg"
compileSdkVersion 19
buildToolsVersion '19.0.3'
dexOptions {
// Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
preDexLibraries = preDexEnabled && !isTravis
}
defaultConfig {
packageName "com.test"
minSdkVersion 9
targetSdkVersion 19
versionCode Integer.parseInt(VERSION_CODE)
versionName VERSION_NAME
buildConfigField "String", "GIT_SHA", "\"${GITSHA}\""
buildConfigField "String", "BUILD_TIME", "\"${BUILD_TIME}\""
testPackageName "com.whosampled.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testFunctionalTest true
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
signingConfigs {
debug {
storeFile file("../test.keystore")
storePassword "#2U3aD+2ASwayEwa"
keyAlias "debug"
keyPassword "gu*W5cUkUM-&5bre"
}
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable false
jniDebugBuild false
zipAlign true
buildConfigField "String", "YOUTUBE_API", "\"${YOUTUBE_DEV_API}\""
}
debug {
signingConfig signingConfigs.debug
debuggable true
jniDebugBuild true
runProguard false
zipAlign false
packageNameSuffix ".debug"
versionNameSuffix "-" + GITSHA + "-debug"
buildConfigField "String", "YOUTUBE_API", "\"${YOUTUBE_DEV_API}\""
}
android.applicationVariants.all { variant ->
println "*********" + variant.getVariantData().getVariantConfiguration().getBuildType().isDebuggable() + "**********";
}
if (false) {
// change apk off build variant.
android.applicationVariants.all { variant ->
println "*********" + variant.description + "**********";
def variants = variant.baseName.split("-");
variant.buildType
def apkName = "whosampled-";
apkName += variants[0];
apkName += "-v" + android.defaultConfig.versionName;
apkName += "-" + GITSHA;
if (!variant.zipAlign) {
apkName += "-unaligned";
}
// if created by build server or something
if (false && variant.buildType.name == "release") {
apkName += "-RELEASE.apk";
} else if (false && variant.buildType.name == "debug") {
apkName += "-SNAPSHOT.apk";
} else {
apkName += ".apk";
}
println "*********" + "$project.buildDir/apk/" + apkName + "**********";
variant.outputFile = file("$project.buildDir/apk/" + apkName)
}
}
}
}
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/groups/public/' }
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.squareup.retrofit:retrofit:1.5.0'
compile 'com.squareup.picasso:picasso:2.2.0'
compile 'com.squareup.okhttp:okhttp:1.5.3'
compile 'com.pixplicity.easyprefs:library:1.0#aar'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'se.emilsjolander:stickylistheaders:2.3.0'
compile 'com.squareup:otto:1.3.4'
compile 'com.pixplicity:font.text.utils.library:1.2#aar'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'com.squareup:fest-android:1.0.+'
}

Categories

Resources