I would like to remove unused resources from my final release apk file created. I am able to configure proguard but its limited to Java files only. I would like to remove unused layouts, strings, pngs etc Any ideas?
I read android link can help; got the script here: http://yltechblog.blogspot.in/2012/06/remove-unused-resource-from-android.html but i donnot know how to integrate it with gradle.
Similarly: https://code.google.com/p/android-unused-resources/; claims to help; but i am unable to figure out how to integrate it with gradle.
My gradle file is as follows
// COMMANDS::
// gradle --build-file adt_build.gradle clean build
// adb -e install -r build/apk/rpsl-debug-unaligned.apk
buildscript {
repositories {
mavenLocal()
maven { url 'http://repo1.maven.org/maven2' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
apply plugin: 'eclipse'
def artifactoryurl='http://10.10.8.10:8081/artifactory'
repositories {
mavenLocal()
maven { url 'http://repo1.maven.org/maven2' }
mavenCentral()
maven {url "$artifactoryurl/jfrog-libs"}
maven {url "$artifactoryurl/plugins-release"}
maven {url "$artifactoryurl/libs-local"}
}
dependencies {
compile 'com.google.code.gson:gson:2.2.4' , 'android:support:v4', 'wavecrest.mobile.libraries:libraries:2'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
signingConfigs {
debugconfig {
storeFile file("../configs/keystore.jks")
storePassword "asdf"
keyAlias "rpsl"
keyPassword "asdf"
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
signingConfig signingConfigs.debugconfig
zipAlign true
runProguard true
proguardFile file('configs/proguard-android.txt')
}
release {
signingConfig signingConfigs.debugconfig
zipAlign true
runProguard true
proguardFile 'configs/proguard-android-optimize.txt'
}
}
defaultConfig {
versionCode 1
}
sourceSets {
main {
manifest{
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res.srcDirs = ['res']
}
instrumentTest.setRoot('tests')
}
}
Lint support is not complete yet with the android gradle plugin. It is scheduled for next release.
From there, you might be able to use the lint results. In gradle to execute a script do something like 'script'.execute()
Related
on android studio, everything works fine and also builds debug apk. But when building signed application this error arrives. I have working Internet connection and I have tried this question and questions mentioned in it.
its an exported generated by unity project so all dependencies are in one gradle file. Here is it:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
repositories {
jcenter()
google()
maven {
url "https://jitpack.io"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
google()
maven {
url "https://jitpack.io"
}
}
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'org.codehaus.groovy:groovy-all:2.4.12'
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
applicationId 'com.Company.MVPA'
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
versionCode 1
versionName '0.1'
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress '.unity3d', '.ress', '.resource', '.obb'
}
buildTypes {
debug {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
jniDebuggable true
}
release {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
signingConfig signingConfigs.debug
}
}
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
doNotStrip '*/x86/*.so'
}
}
this line added from an answer : "implementation 'org.codehaus.groovy:groovy-all:2.4.12" but it shows the mentioned error. But without it, it shows following error (only while building a signed apk):
`Could not find org.codehaus.groovy:groovy-all:2.4.12.
Searched in the following locations:
file:/C:/Users/RAM/AppData/Local/Android/sdk/extras/m2repository/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.pom
file:/C:/Users/RAM/AppData/Local/Android/sdk/extras/m2repository/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar
file:/C:/Users/RAM/AppData/Local/Android/sdk/extras/google/m2repository/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.pom
file:/C:/Users/RAM/AppData/Local/Android/sdk/extras/google/m2repository/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar
file:/C:/Users/RAM/AppData/Local/Android/sdk/extras/android/m2repository/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.pom
file:/C:/Users/RAM/AppData/Local/Android/sdk/extras/android/m2repository/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar
file:/F:/Android/MVPA/Android/MVPA/libs/groovy-all-2.4.12.jar
file:/F:/Android/MVPA/Android/MVPA/libs/groovy-all.jar
https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.pom
https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar
https://jitpack.io/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.pom
https://jitpack.io/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar
Required by:
project : > com.android.tools.lint:lint-gradle:26.2.1
`
How to build a signed apk solving this problem?
add jcenter to repositories, among implementation line.
allprojects {
repositories {
jcenter() //this
flatDir {
dirs 'libs'
}
google()
maven {
url "https://jitpack.io"
}
}
I have one flavor for specific device. For this device I have .jar file which have custom android sdk(for this device. It contains some custom class which I have to use). And it works fine until I start use proguard. When I build project with proguard I receive this:
...
Note: there were 1504 duplicate class definitions.
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:proguardAppProguard'.
> java.io.IOException: Please correct the above warnings first.
I found that adding a string:
-ignorewarnings
to proguard-android.txt fixes this problem, but it looks like bad solution. Did somebody face this(or similar) problem?
Edit
build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
flatDir {
dirs 'libs'
}
}
apply plugin: 'idea'
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
def computeVersionName() {
return "r_1.0"
}
android {
compileSdkVersion 23
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.app"
multiDexEnabled true
String buildSuf = System.getenv("BUILD_NUMBER");
ext.defaultName = project.archivesBaseName;
if (buildSuf != null) {
def vers = Integer.parseInt(buildSuf)
println "VERCODE = ${vers}"
versionCode vers
} else {
versionCode 1000
}
minSdkVersion 16
targetSdkVersion 21
}
productFlavors {
app {
applicationId "com.app"
versionName computeVersionName()
}
}
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
disable 'InvalidPackage'
}
signingConfigs {
...
customerProgurd {
storeFile file('../keys/debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
...
}
buildTypes {
...
customerProguard {
debuggable false
jniDebuggable false
minifyEnabled true
proguardFiles rootProject.file('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.customerProgurd
}
...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
...
app files('libs/classes.jar') // it's custom sdk
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
...
}
I want to run the app without clicking on "generate signed apk..."
My project structure is :
I want to run 'main' sourceSet
I use in Built Variants 'release',
run,
But error is:
The APK file ...\zastavokNet\build\outputs\apk\zastavokNet-release.apk does not exist on disk.
Here is my gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'org.tmatesoft.svnkit:svnkit-cli:1.8.7'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.***"
minSdkVersion 14
targetSdkVersion 22
versionName "1.0."
versionCode 1
}
signingConfigs {
release {
storeFile file("***\\key.jks")
storePassword "***"
keyAlias "***"
keyPassword "***"
}
}
repositories {
maven {
url "https://mint.splunk.com/gradle/"
}
}
buildTypes {
release {
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'
}
debug {
debuggable true
signingConfig android.signingConfigs.debug
}
}
sourceSets {
main {
manifest.srcFile '/src/main/AndroidManifest.xml'
java.srcDirs = ['/src/main/java']
res.srcDirs = ['/src/main/res']
assets.srcDirs = ['/src/main/assets']
}
debug {
manifest.srcFile '/src/main/AndroidManifest.xml'
res.srcDirs = ['/src/debug/res']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Often times doing a clean (Build > Clean Project) then rebuilding will fix issues such as this.
If it doesn't, you should also try updating your build tools- 21.1.2 is pretty old. The latest is 23.0.1. While you are at it, check your top-level build.gradle and make sure you are using the latest Gradle plugin version (1.3.1, the com.android.tools.build:gradle dependency).
I had a similar issue after playing with flavors and splits in my build.gradle. And for me switching to another branch and going back fixed the problem
I am having trouble getting a signed zipaligned gradle file built in my Android app. I am using intellij 13.1.4. The error I am receiving is Error:(34, 0) Could not find property 'configstd' on BuildTypeDsl_Decorated{name=release, debuggable=false, jniDebugBuild=false, renderscriptDebugBuild=false, renderscriptOptimLevel=3, packageNameSuffix=null, versionNameSuffix=null, runProguard=false, zipAlign=true, signingConfig=null}.
Here is my build.gradle:
` buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
signingConfigs {
configstd {
keyAlias 'myalias'
keyPassword 'mykeypassword'
storeFile file('mykeyfile.jks')
storePassword 'mystorepassword'
}
}
buildTypes {
release {
debuggable false
zipAlign true
signingConfig configstd
}
debug {
debuggable true
zipAlign false
signingConfig configstd
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile 'com.android.support:appcompat-v7:19.+'
}
`
Here is what I discovered to be the problem. I originally had used the intellij's Project Structure->Facets->Android-Gradle to enter the parameters for the build.gradle file. Apparently, when it created the code to insert into the file it left off "signingConfigs" from the name of the object configstd. So in other words the line should read as follows:
signingConfig signingConfigs.configstd
In reference to this post, does anyone have a pair of build.gradle files that demonstrate the basic setup for referencing Crashlytics from a android library project?
I get the following error even though I followed the recommendation provided via the post originally mentioned above.
This is my App gradle.build file.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile project(':Common.Logger')
compile project(':Common.ProtocolBuffer')
compile project(':Common.Utils')
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v4:+'
compile 'com.crashlytics.android:crashlytics:1.+'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile 'junit:junit:4.11'
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
buildTypes {
debug {
buildConfigField "boolean", "USE_LOGCAT", "true"
buildConfigField "boolean", "USE_CRASHLYTICS", "false"
ext.enableCrashlytics=false
}
release {
runProguard true
debuggable false
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
buildConfigField "boolean", "USE_LOGCAT", "false"
buildConfigField "boolean", "USE_CRASHLYTICS", "true"
ext.enableCrashlytics=true
}
}
sourceSets {
packagingOptions {
exclude 'LICENSE.txt'
}
lintOptions {
abortOnError false
}
}
}
This is my current Library build.gradle file.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile 'com.crashlytics.android:crashlytics:1.+'
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
buildTypes {
debug {
buildConfigField "boolean", "USE_LOGCAT", "true"
buildConfigField "boolean", "USE_CRASHLYTICS", "false"
ext.enableCrashlytics=false
}
release {
buildConfigField "boolean", "USE_LOGCAT", "false"
buildConfigField "boolean", "USE_CRASHLYTICS", "true"
ext.enableCrashlytics=true
}
}
sourceSets {
lintOptions {
abortOnError false
}
}
}
I was told by Crashlytics support some time ago to simply use the 'ext.enableCrashlytics' flag in a buildType.
The following is the current gradle error that occurs using the above gradle build files.
Error:A problem occurred configuring root project 'ManageMyVMail.Android'.
> A problem occurred configuring project ':Common.ProtocolBuffer'.
> Could not resolve all dependencies for configuration ':Common.ProtocolBuffer:_debugCompile'.
> Could not find any version that matches com.crashlytics.android:crashlytics:1.+.
Required by:
ManageMyVMail.Android:Common.ProtocolBuffer:unspecified > ManageMyVMail.Android:Common.Logger:unspecified
As a secondary question, do I need to create the same set of buildConfigField values in both files if I want to use them from both projects after I get past the current gradle build error. I am fairly new to Gradle and Android Studio, but searching the Intertron just has not produced an answer yet.
Thank you in advance.
After a few emails with Crashlytics support, I found a solution. There were two aspects to the final solution.
The error message originally posted was stating the situation, I was just not reading it correctly. Simply, the library project that did not need Crashlytics depended on the other library project that did need Crashlytics. Adding the Crashlytics dependency to the aforementioned library solved the Gradle build issue.
The Crashlytics API key had to be added to the library project manifest depending on Crashlytics. The project built, but did not submit my "log" messages at runtime, so this was an obvious fix once I made the connection.
I have included the Gradle files from each of the (3) projects involved in my scenario. Hope this helps others and thanks to Mike at Crashlytics for responding to my messages.
App.gradle (calls Crashlytics.start())
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile project(':Common.Logger')
compile project(':Common.ProtocolBuffer')
compile project(':Common.Utils')
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v4:+'
compile 'com.crashlytics.android:crashlytics:1.+'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile 'junit:junit:4.11'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
buildTypes {
debug {
buildConfigField "boolean", "USE_CRASHLYTICS", "false"
}
release {
buildConfigField "boolean", "USE_CRASHLYTICS", "true"
runProguard true
debuggable false
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
sourceSets {
packagingOptions {
exclude 'LICENSE.txt'
}
lintOptions {
abortOnError false
}
}
}
Common.Logger.gradle (calls Crashlyics.log())
apply plugin: 'android-library'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile 'com.crashlytics.android:crashlytics:1.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
buildTypes {
debug {
ext.enableCrashlytics = false
}
release {
ext.enableCrashlytics = true
}
}
sourceSets {
lintOptions {
abortOnError false
}
}
}
Common.ProtocolBuffer.gradle (depends on Common.Logger, no Crashlytics calls)
apply plugin: 'android-library'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile 'com.google.protobuf:protobuf-java:2.4.1'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.crashlytics.android:crashlytics:1.+'
compile project(':Common.Logger')
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
sourceSets {
lintOptions {
abortOnError false
}
}
}