Avoid shrinking/removing wearable micro app from apk file - android

I activated the resouce shrinking in my build.gradle but now my embeded wearable app is stripped out. How can I avoid that my micro app is removed, because it is unused?
Skipped unused resource res/raw/android_wear_micro_apk.apk: 382310 bytes
Since I want to shrink the other not used resouces I'm using this DSL:
buildTypes {
release {
shrinkResources true
// ...
}
}
I would guess that I need to use proguard but I have no idea how to achieve that. I checked of cause the documentation, but I didn't get it how protect a single member variable.

Are you referencing the R.raw.apkpath? Looking at the Packaging Wearable Apps training mentions rawPathResId in the res/xml/wearable_app_desc.xml
On a side note enabling proGuard is simple with Gradle
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

This is Bug 78620 and was fixed in the gradle build tools 0.14.1.

Related

Android - What is the purpose of multiDexKeepProguard ? How does it compare to proguardFiles close in gradle?

I have created a multidex app. But in regards to proguard i have the following in build.gradle:
android {
defaultConfig {
...
multiDexEnabled true
}
productFlavors {
dev {
// Enable pre-dexing to produce an APK that can be tested on
// Android 5.0+ without the time-consuming DEX build processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the production version.
minSdkVersion 14
}
}
buildTypes {
release {
minifyEnabled true
*** proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
My question is about the progardFiles vs using multiDexKeepProguard. The documentation states:
File multiDexKeepProguard
Text file with additional ProGuard rules to be used to determine which
classes are compiled into the main dex file.
If set, rules from this file are used in combination with the default
rules used by the build system.
So if i do not use the multiDexKeepProguard then my classes still get compiled but may not end up in the main dex file, is that correct ? I am not clear how this differs from proguardFiles.
Android documentation also references this.
If you're enabling proguard in your application it's usually necessary to define proguard rules. proguardFiles are meant to be the instructions for progurard to minify or obfuscate your app.
multiDexKeepProguard is specifically for telling multidex which files are important to load at app startup and therefore what to keep in the main dex. As far as i'm aware, it just uses the proguard syntax as a convenience. This is optional and will usually only be set if there is an issue at runtime.

Android Debugger - Firebase objects are obfuscated

I currently have an Android App that is using Firebase Auth. After google login, I get a FirebaseUser object. If I set a breakpoint and look at the object. I see obfuscated objects and values. See image:
Proguard is disabled for debug so I'm guessing that is not the issue:
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Anyone know what I might be doing wrong? Any help is much appreciated!
Firebase library files are obsuscated themselves. You cannot really do anything about it. I guess Google does not want to make everything from their libraries public due to security reasons or using the library incorrectly.

Android Gradle 2.2 Not Allowing ShrinkResources for Signed APK

As part of the Android Studio 2.2 roll out I updated my Gradle Build tools to v2.2. After doing that my signed APK build process fails because I have shrinkResources = true.
Once I switch back to Gradle v2.1.3 OR set shrinkResources = false everything works fine. Here's my app gradle build file:
android {
signingConfigs {
}
compileSdkVersion 24
buildToolsVersion '24.0.0'
defaultConfig {
applicationId "com.sample.testapp"
minSdkVersion 21
targetSdkVersion 24
versionCode 4
versionName "0.0.4"
}
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile 'C:/Users/code/testapp/app/proguard-rules.pro'
}
}
productFlavors {
}
}
With Gradle set to v2.2 here's the build error I get when generating a signed APK
Does anyone know why this is occurring and if there's a work around? I've Googled around a bit and have seen some older Android Bug reports about alpha and beta Gradle builds having this issue, but the reports I found were >6 months old (and for previous Gradle versions).
P.S. I know that minifyEnabled = false currently, i have yet to investigate the correct set of proguard rules for my included libraries to prevent the Signed Build from erroring out due to missing libs.
To use shrinkResources you have to use minifyEnabled
As per Android documentation:
Resource shrinking works only in conjunction with code shrinking.
After the code shrinker removes all unused code, the resource shrinker
can identify which resources the app still uses. This is especially
true when you add code libraries that include resources—you must
remove unused library code so the library resources become
unreferenced and, thus, removable by the resource shrinker.
To enable resource shrinking, set the shrinkResources property to true
in your build.gradle file (alongside minifyEnabled for code
shrinking).
use
minifyEnabled false
shrinkResources false
or
minifyEnabled true
shrinkResources true
may be a bug on android gradle plugin
wait google fix bugs

Is it possible to have one proguard mappings.txt file for multiple flavor?

I would like to publish my app to multiple market. the version code should be same in all market and my app has IAP so i should have multiple flavor and one manifest per flavor.
And also i need the mapping file for the crash report(for example in tracepot).
My problem is: How can i have one mappings.txt file for multiple flavor?
build.gradle:
android {
productFlavors {
Market1 {
...
}
Market2 {
....
}
signingConfigs {
debug {
....
}
release {
....
}
}
buildTypes {
debug {
debuggable true
signingConfig signingConfigs.debug
}
release {
debuggable false
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Yes, the current settings in your build.gradle will apply the proguard file to all release builds of all flavors. You already have it there.
Update after the conversation with OP in comments below:
Now i understood the question better. You are trying to have a single mapping.txt file and are not talking about the proguard-rules.pro. The answer is No, you cannot have a single file for multiple generated apks. Proguard rules are applied to each flavor separately and each time it generates a separate mapping file. There might not be a any differences in your mapping.txt files right now because you may not be using different sourceSets (Java classes). But, if you have different sourceSets, the mappings.txt file will not be the same. Probably you have only minimal difference between your flavors right now like different drawables with same name, If i'm assuming right.

This application does not have the debuggable attribute enabled in its manifest

Cannot debug application com.domain.test on device samsung-gt_i9300-323020cfc86b804f.
This application does not have the debuggable attribute enabled in its manifest.
If you have manually set it in the manifest, then remove it and let the IDE automatically assign it.
If you are using Gradle, make sure that your current variant is debuggable.
Your comment has already hinted the answer to this post but since you have not selected an answer I'll write it down.
Change build variant from release to debug from android studio left corner.
A right solution is written in https://stackoverflow.com/a/25628789/2914140:
open build.gradle of your module, type: 'debuggable true' (an example is below):
buildTypes {
release {
signingConfig signingConfigs.release
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
When you generate a signed APK from menu, you should edit 'release' branch changing 'debuggable true' to false in order to avoid a debuggable information.
In build.gradle
debug {
debuggable true
signingConfig signingConfigs.debug
}
for whose came here searching TS's quote, check if you set Android Application in Run/Debug configuration popup. Not Native, like in my mistake.

Categories

Resources