aapt_rules.txt not found: libGDX project on IntelliJ Idea - java

I'm facing this problem when I try to build a project for which I've added support for proguard in my android/build.gradle file as follows:
// Proguard configuration
buildTypes {
release {
//minifyEnabled true will turn proguard ON
minifyEnabled true
//proguardFiles let you add your own proguard rules ('proguard-project.txt') in this case, as its already created by gdx-setup
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
I've no proguard-android.txt file, but I do have a proguard-project.txt file within the same android module directory with the following text:
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.parentDir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-verbose
-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-dontwarn com.badlogic.gdx.utils.GdxBuild
-dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
-dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild
-keep class com.badlogic.gdx.controllers.android.AndroidControllers
-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
<init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}
-keepclassmembers class com.badlogic.gdx.physics.box2d.World {
boolean contactFilter(long, long);
void beginContact(long);
void endContact(long);
void preSolve(long, long);
void postSolve(long, long);
boolean reportFixture(long);
float reportRayFixture(long, float, float, float, float, float);
}
The error I get is this:
Warning:Exception while processing task java.io.FileNotFoundException:
/home/.../Desktop/Idea/.../android/build/intermediates/proguard-rules/release/aapt_rules.txt
(No such file or directory)
I've seen other's problem is that they have an empty proguard rules file, but this is clearly not the case.
Any ideas on how I could debug this?
Thanks a lot in advance!

The solution I found to this problem was to delete the android/build directory inside my project altogether, before "Invalidate Cache/Restart..." in the File menu. I've tried several times that menu option before without deleting the android/build directory and it made no difference at all.
Rebuilding the project didn't work either despite having the checkbox "Clean project on rebuild" enabled, so it seems that sometimes to get a clean project in IntelliJ Idea you have to do it by yourself.

Related

How to configure 'build_common.xml' Ant file for Proguard and ORMLite in java application

I have a Java application running on PC (Windows).
I use Netbeans.
I use Proguard to obfuscate the code and I configure the obfuscation by the build_common.xml (Ant) file; therefore the ProGuard configuration options are given by XML configuration tags.
I'm not expert at all of Xml, Proguard, I just copied and adapted some pieces of codes got in the web for my purposes and it worked.
Recently I introduced in my code ORMLite. When I run from IDE (so without obfuscation) my code works, but when I build with obfuscation it doesn't work.
Inside build_common.xml I excluded the "class com.j256.**" library, by:
<keep name="com.**" > <method name="*" /> <field name="*" /> </keep>
but it isn't enought because probably ORMLite uses special annotations.
I found out some post, suggesting to use for example:
-keepattributes *DatabaseField*
-keepattributes *DatabaseTable*
-keepattributes *SerializedName*
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
-dontwarn com.j256.ormlite.logger.**
-dontwarn com.j256.ormlite.misc.**
but I don't know how to write those options in XML; I did some trying but it didn't work.
Can anybody help? Moreover on how to exclude from obfuscation ORMLite annotations.
Founded out the solution:
simply added inside the proguard tags of 'build_common.xml' file the line:
-keepattributes *Annotation*
`the rest of the lines mensioned in my question seems unusefull

ProGuard SimException

I'm trying to get ProGuard to work, after roughly 4 hours of randomly trying options to try and get this amazing software to work.
My project is using LibGDX and KryoNet. This is my current ProGuard configuration:
-verbose
-dontobfuscate
-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-dontwarn com.badlogic.gdx.utils.GdxBuild
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
-dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild
-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
<init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}
# Kryo
-dontwarn sun.reflect.**
-dontwarn java.beans.**
-dontwarn sun.nio.ch.**
-dontwarn sun.misc.**
-keep class com.esotericsoftware.kryo.** {*;}
-keep class com.esotericsoftware.** {*;}
-keep class java.beans.** { *; }
-keep class sun.reflect.** { *; }
-keep class sun.nio.ch.** { *; }
This does not compile. It throws multiple of the following errors: Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type float using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.
I found some information about this error: Compile with Proguard gives SimException: "local variable type mismatch".
The solution given was to edit some main-rules.xml file from ANT, but I'm using Gradle. A comment was posted with a fix for Gradle : to add project.tasks.withType(com.android.build.gradle.tasks.Dex) { additionalParameters=['--no-locals'] }. But apparently the Dex class is removed, so this no longer works.
I read this is a bug in ProGuard, and that obfuscating should fix it. But when I remove the -dontobfuscate line, my app does not start anymore: java.lang.UnsatisfiedLinkError: No implementation found for void com.a.a.c.a.k.g() (tried Java_com_a_a_c_a_k_g and Java_com_a_a_c_a_k_g__).
Does anyone know how to work around these issues?
The problem might be related to a specific optimization of ProGuard.
You can disable it like that:
-optimizations !code/allocation/variable
Furthermore you can also remove the LocalVariableTable and LocalVariableTypeTable attributes which do not seem to be updated properly (and are not needed in an application anymore). For this you would need to enable obfuscation though and then use something like:
-keepattributes !LocalVariable*,**
This rule would keep all attributes but the LocalVariable related ones.
The obfuscation problem with libGDX might be solved by this rule:
# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,includedescriptorclasses class * {
native <methods>;
}

Error Java.io.IOException for Admob on app

I would put admob adverts in my app, I did everything correctly but when I try to export the .apk:
Error:Execution failed for task ':app:proguardRelease'.
> java.io.IOException: Please correct the above warnings first.
My "proguard-project" is:
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
# -keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
# AdMob Support
-keep class com.google.ads.**
-dontwarn com.google.ads.**
-dontwarn com.google.android.gms.**
Any help?
Is the first time that i write in this blog, I hope I do not have anything wrong
EDIT:
there are also 2 warnings
:app:proguardRelease
Warning:com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning:com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning:com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning:there were 2 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 2 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
:app:proguardRelease FAILED
Error:Execution failed for task ':app:proguardRelease'.
> java.io.IOException: Please correct the above warnings first.

EventBus onEvent() not found after deployment

I am developing in Java using Eclipse Luna SR1. The app was tested successfully on a physical device. However, after I deployed it, I received the ClassNotFoundException claiming there's no onEvent() method in my activity...but it's there.
Did anyone encounter the same problem?
When using proguard you need to add this to proguard.config
## GreenRobot EventBus specific rules ##
# https://github.com/greenrobot/EventBus/blob/master/HOWTO.md#proguard-configuration
-keepclassmembers class ** {
public void onEvent*(***);
}
# Only required if you use AsyncExecutor
-keepclassmembers class * extends de.greenrobot.event.util.ThrowableFailureEvent {
public <init>(java.lang.Throwable);
}
# Don't warn for missing support classes
-dontwarn de.greenrobot.event.util.*$Support
-dontwarn de.greenrobot.event.util.*$SupportManagerFragment
official documentation https://github.com/greenrobot/EventBus/blob/master/HOWTO.md#proguard-configuration

Configuring ProGuard for android-eclipse project with multiple jars

I want to use ProGuard for my android app, but I have some trouble with it. When I build an unsigned apk via android tools (in eclipse) I got following errors:
Warning: com.millennialmedia.android.NVASpeechKit$7: can't find referenced class com.nuance.nmdp.speechkit.Recognizer
[...] //more warnings of the same type as above
You should check if you need to specify additional program jars.
Warning: there were 170 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:321)
at proguard.ProGuard.initialize(ProGuard.java:211)
at proguard.ProGuard.execute(ProGuard.java:86)
at proguard.ProGuard.main(ProGuard.java:492)
I'm using 5 jar files within my app, which are all located in the libs-folder and are added to the build-path (So they propably appear in 'Referenced Libraries' as well as 'Android Private Libraries' again). Additionally, I put a so-library in libs/armeabi...
My proguard - file look pretty normal, yet:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontpreverify
-dontskipnonpubliclibraryclasses
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** e(...);
}
What should I do to fix this error?
regards
PS: I know that proguard can delete/change some important things (like class-files,..). So, will I notice such 'errors' by exceptions immediately when starting my app or do I have to check every detail and navigate to any part of my app at runtime to make sure that it runs as it should?
EDIT:
I'm using following jars:
alljoyn.jar (there's also a path varibale in linked resources to the alljoyn-sdk)
peergroupmanager.jar
android-support-v4.jar
MMSDK.jar
GoogleAdMobAdsSdk-6.4.1.jar
From http://docs.millennialmedia.com/android-SDK/AndroidFAQ.html
I am using ProGuard with my Android application, what should I do to ensure my Millennial ads still work?
To make sure you still receive ads while using ProGuard, add the following snippet to your proguard.cfg file.
-keepclassmembers class com.millennialmedia.android.* {
public *;
}
-keep class com.millennialmedia.android.**
When using ProGuard and not SpeechKit, add the following line to their proguard-project.txt:
-dontwarn com.millennialmedia.android.NVASpeechKit*

Categories

Resources