Ignore method during Proguard Obfuscation - obfuscation

I have been trying desperately to ignore the following method during Proguard obfuscation:
package com.foo.me;
public class MyClass extends Activity implements Callback {
...
public void setButtonColor(String color, Button button){
...
}
...
}
I feel like I've been through all the answers here with no luck. Can any share the correct statement to skip over this method with Proguard?
Thanks,
Josh

You can keep ProGuard from removing or renaming the class and the method with this configuration:
-keep class com.foo.me.MyClass {
public void setButtonColor(java.lang.String, android.widget.Button);
}
See the ProGuard manual > Examples > Processing callback methods

Related

Powermock of static class gives error: java.lang.NoClassDefFoundError: Could not initialize class XXX

Problem
Could not initialize class ...
...javax.xml.transform.FactoryFinder (in our case).
In the article, where we found the solution, it was the class SessionFactory.
Class Under Test
We wanted to write a test for a utils class with static members.
We got the error when trying to create a Mock of a class, which contained a new statement as an initialization of a static field.
public class ClassUnderTest{
private static JavaType javaType = new JavaType();
// ...
}
Test Class
#RunWith(PowerMockRunner.class)
#PrepareForTest(ClassUnderTest.class)
public class TestForClassUnderTest {
#Test
public void testCase() {
PowerMockito.mockStatic(ClassUnderTest.class);
Solution
The solution was adding another class level annotation to the test class:
#SuppressStaticInitializationFor("com.example.package.util.ClassUnderTest")
Note, that you have to give the package path and no .class at the end. Unlike #PrepareFor.
Thanks to this article: http://www.gitshah.com/2010/06/how-to-suppress-static-initializers.html
Test Class with Solution
//...
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
#RunWith(PowerMockRunner.class)
#PrepareForTest(ClassUnderTest.class)
#SuppressStaticInitializationFor("com.example.package.util.ClassUnderTest") // <-- this is it :)
public class TestForClassUnderTest {
#Test
public void testCase() {
PowerMockito.mockStatic(ClassUnderTest.class);
//...
}
}

Adding aar library into cn1lib project

We're currently coding a cn1lib for OpenTok framework, but we're stuck at the inclusion of the required libraries.
We need the appcompat-V7-18.0.0.aar and support-v4-18.0.0.jar in order to use the opentok-android-sdk-2.11.0.aar, but we failed at including them.
We get this log from the CN1 build server and use this codenameone_library_appended.properties :
codename1.arg.android.proguardKeep=-keep class android.support.v4.** { *; } -keep class android.support.v7.** { *; } -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.app.Activity -keep public class * extends android.preference.Preference -keepclassmembers class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.READ_LOGS" /> <uses-permission android\:name\="android.permission.ACCESS_NETWORK_STATE" />
We think that something is missing in this file, but what ? At this time we're just trying to do the android part, iOS later.
Any idea will be helpful, thanks in advance :)
While there are instructions on adding AAR files in the developer guide this isn't the answer you need... Support libraries are a special case. You probably don't need these build hints either.
Check out these build hints for the Intercom cn1lib:
codename1.arg.java.version=8
codename1.arg.ios.pods=Intercom
codename1.arg.ios.pods.platform=8.0
codename1.arg.android.buildToolsVersion=25.0.1
codename1.arg.android.playServicesVersion=9.8.0
codename1.arg.android.supportv4Dep=compile 'com.android.support\:support-v4\:25.+'
You can define a different version of play services and build tools, I'm guessing 25 will be new enough to support the requirements of this library.

Codename one separate class along with statemachine class

I am working a project in gui builder..As my project is growing bigger and bigger, i find it hard to search a particular forms and methods all in a statemachine class. so i wanted to create a separate class for each form. but since the gui builder create the methods automatically in statemachine which extends statemachineBase class. how can i use separate class for separate gui forms so that they automatically create methods in the designated class. for instance when i click before show event of form named "NextPage", the gui builder automatically create beforeNextPage method in NextPage class instead of statemachine. I did the followings but lost in the process..
NextPage.class
public class NextPage extends StateMachine {
private ArrayList<Map<String, Object>> mData;
private ArrayList<Map<String, Object>> moreData;
public NextPage(String resFile) {
super(resFile);
}
#Override
public void beforeNextPage(Form f) {
//.........
}
}
Forms generated by GUI Builder cannot be separated from StateMachineBase into different Classes.
What I do personally is create a form in GUI to get the right Look and Feel and then create a replica of that form in code, then delete the one on GUI Builder once I'm satisfied with the code version. It makes my projects well organized and easy to debug.
BeforeShow() would be handle while the form class is loading and to do anything in PostShow(), just do this:
this.addShowListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
removeShowListener(this);
//Your postShow() codes here.
revalidate();
}
});
Forms created in code are light-weight and more customizable than GUI forms.

Resolve region manager in wpf

I am trying to do this in a specflow step definition file, so that I can create an object of view model and make method calls to it.
But I get an error saying "Interface cannot be resolved: Microsoft.Practices.Prism.Regions.IRegionManager (resolution path: TestClass)". What is that I am doing wrong?
public class TestClass
{
private IRegionManager _RegionManager;
[ImportingConstructor]
public TestClass(IRegionManger regionManager)
{
this._RegionManager = regionManager;
// stuff here
}
}
Are you expecting your test class to be instantiated by SpecFlow or via Prism? As both have dependency injection functionality.
So I wouldn't expect your test definition file to have any importing constructors or similar MEF attributes. Instead I would expect your test class to written more like
[Binding]
public class TestClass
{
[Given("I setup Prism")]
public void GivenISetupPrism()
{
// Call into prism
}
}
See the documentation on http://specflow.org for more details.

How to avoid that proguard obfuscates the classes annotated with #OnStart

In applications based on NetBeans Platform 7.2, it is possible to
replace the ModuleInstall classes with this code:
import org.openide.modules.OnStart;
import org.openide.modules.OnStop;
#OnStart
public final class Installer implements Runnable {
#Override
public void run() {
System.out.println("enable something...");
}
#OnStop
public static final class Down implements Runnable {
#Override
public void run() {
System.out.println("disable something...");
}
}
}
My problem is that, after obfuscation, the class loader does not find
the annotated classes.
In the Proguard configuration I added (as suggested here)
-keep #org.openide.modules.OnStart class *
But apparently this is not enough or it does not work.
Does anybody have a suggestion?
From I could figure out, you need to explicitly keep the annotations that you use to keep whatever specifications. So, in your case, adding
-keep enum org.openide.modules.OnStart
would allow this annotation to be used as a selector.
Proguard really ought to include a warning message if annotation selectors are not actually matching. It also doesn't really make sense to keep the annotation, especially if it's not of runtime retention.
Have you tried -keepattributes *Annotation*? It might do the trick, based on proguard usage.

Resources