EventBus onEvent() not found after deployment - java

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

Related

aapt_rules.txt not found: libGDX project on IntelliJ Idea

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.

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>;
}

Proguard warnings despite kept classes

I'm using Proguard to shrink my code. My strategy is to enable it and then follow the warnings to keep anything it complains about. If there are outside libraries, I try to follow the Proguard instructions the authors make available. Many instructions include a -dontwarn flag. If I disable the -dontwarn flag, I will get warnings. If we are keeping most classes via -keep flag, why do warnings still come up?
Example:
-keep class javax.** { *; }
# for butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.AbstractProcessor
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.lang.model.element.TypeElement
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.lang.model.element.Element
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.Filer
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.tools.JavaFileObject
...
There are many warnings in ProGuard meaning different things. This particular one:
Warning:A: can't find referenced class B
Means that while ProGuard was processing class A it encountered reference to class B. But class B wasn't included as a source (-injars class_path) or as a library (-libraryjars class_path).
First note that for this particular warning in case of standard Android build chain adding -keep rules will not help. ProGuard transitively keeps referenced code.
This warning can happen for several reasons. Often a library X can contain code that uses another library Y. And X uses Y optionally - only when Y is present on the classpath, X doesn't enforce presence of Y. This way ProGuard is unable to find classes from Y.
To get rid of the warnings you have to either add Y as a dependency or ignore the relevant warnings.
In case of ButterKnife the situation is slightly different. Butterknife uses annotation processing. And it contains both the library and annotation processor in one dependency (latest version 7.0.1). So class butterknife.internal.ButterKnifeProcessor is still present in the compiled classes (even though it's work is already finished - used during java compilation). And ProGuard tries to process it. ProGuard fails to find the missing classes because they were used only during annotation processing and are not present for ProGuard processing.
In this case it's really necessary to ignore the warnings.

Crashlytics Android: app could not be located

To create an application and has built fabric.io.
My app release 1.1 - everything works, statistics comes.
My app released 1.2 - it does not work, the statistics do not come.
When you come on the dashboard fabric.io:
Alert! Sorry, the app could not be located.
An important point:
If you build debug version - it works!
If the release version of the GoogleStore - is not working! (Although version 1.1 of the GoogleStore - works!)
Checked logcat release version:
Logcat: I/Fabric: Initializing Crashlytics 2.2.2.37
What could be wrong? How to solve this problem?
Thank you!
If you are building a release version and using ProGuard you should add following lines in your ProGuard file:
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
This documentation could be useful for you too Dex and ProGuard and Advanced Setup.

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