I am attempting to obfuscate an Android Library Project (APKLIB), allowing the library to distributed to potential clients for test development without compromising the majority of the source code.
Unfortunately, there is no documentation and no examples that Google can provide, and the only references to obfuscated APKLIBs are question posts with no solutions.
I have attempted to use the android-maven-plugin as well as the maven-proguard-plugin with Maven to obfuscate the APKLIB, but the end result is not obfuscated. I also tried moving the proguard goal to the process-classes and prepare-package phases of maven with no success.
My last resort is splitting the source code out of the APKLIB and obfuscating it as a JAR, while leaving the APKLIB as AIDL files and resources with a dependency on the obfuscated JAR. However, I would like to avoid this if possible since our project has a large number of libraries already.
Does anyone know if it is even possible to obfuscate an APKLIB? And if so, how?
Hi are you asking about creating a obfuscated jar file?
You can do that by adding build.xml file to it and making changes in your proguard-project.txt file and running "ant release" from command line and you will find the obfuscated.jar under a proguard folder in your bin folder of project.
Steps;
-> To add build.xml in your project in linux open a terminal and go to android/tools/ant folder and run ./android update project -p /path of your android library project. And you will find build.xml in your project root directory.
-> To enable Obfuscation in your project in your editor open a project.properties file and remove comment from proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-> Add your changes to proguard-project.txt file and in terminal go to your project and run ant release
Related
I created a test project to understand how to build and run the tests using command line tool. I managed to create a project, updated it with
android update project -p .
and debug with
ant debug
When I added a library project to this test project, the ant debug started to fail because it couldn't find the build.xml of the library. The only solution I found atm is to update the library project as well (found here). Is this the correct way? I see pom.xml files in many of the libraries that I use. I know it is used by Maven (although I know nothing about it) and it might help me with another solution.
Ant is the official way to build android apk. Maven is an alternative way of doing it (not officially supported, but it works very well).
There are few differences regarding default project layout when working with maven or ant, but it's possible to have both build system working on the same source code if you do some additionnal configuration work (i.e. some information will be duplicated).
Default project layout with maven
java source files are under `/src/main/java``
dependencies are defined in the pom.xml (using the maven way of defining dependencies, with type apklib for android libraries)
Default project layout with ant (and eclipse ADT plugin)
java source files are under /src
dependencies are defined in /project.properties and are specified using relative path.
Here is an example of project.properties (it's a typical example of a library project referencing 2 other library project):
target=android-15
android.library=true
android.library.reference.1=../somelib
android.library.reference.2=../someOtherLib
(as you can see some additionnal information are stored in this file : the android target and the fact that the project is an library or an app. When you use maven, this information is in the pom.xml)
How to build a maven android lib with ant ?
The problems (when you need to build a maven-layout-android-library with ant) are the following:
having a proper /build.xml (it can be done through android update library-project ... here is the official doc about this command)
having a proper /project.properties (it is partially done by the android update ... command, but you may need to add some android.library.reference by hand or with eclipse ADT plugin)
telling ant that the java source files aren't at the default location, but are under /src/main/java
For this last point, here is how to do it:
create a file /ant.properties (in your maven-layout-android-library)
put the following entry in it:
source.dir=src/main/java
(Important : it is not always required because sometimes the java source files are already under /src in the maven-layout-project and in this case, the pom.xml contains the information that the source dir is /src)
And that's all. Now, your maven-layout-android-library can be build with ant debug
I'm trying to create an Android library JAR and would like to use ant for an automated build.
I noticed that when I use ant release, however, the jar file gets added an extra android/annotation folder with TargetApi.class and SuppressLint.class. This causes problems when I try to run an app with the jar, I get:
java.lang.IllegalArgumentException: already added: Landroid/annotation/SuppressLint;
How can I have ant not try to add these classes which appear redundant?
Specifically, the problem seems to be that ant is including annotations.jar in my lib, then when my other project imports that lib it encounters conflict with its own annotations.jar.
edit:Determined that this is ProGuard-related, as the original.jar it creates doesn't have the annotations.jar classes, but obfuscated.jar does. Still not sure how to bypass this step.
In the ProGuard config, I have it only keep the files from my package name.
I am trying to build my android project using ant in command line mode.
It works with eclipse and it used to work with ant until i installed the latest android sdk.
I run ant release -buildfile projectdir\build.xml. The compilation process is ok, and after aligning the apk, it fails at runtime with ClassDefNotFoundError acra.ACRA.
I have tried to remove any reference to acra from the project, but it will fail at runtime when trying to execute any code coming from a library jar.
My jars are in the libs folder at the root of the project. And I sort of understood this would cause ant to link them into the apk. But it doesn't.
When I used a previous version of the android sdk, I had a file named build.properties with an attribute referencing the jars folder external.libs.dir=libs. But now I can't make this to work any more, even if I use the new attributes names jar.libs.dir=libs and the new attributes file name ant.properties.
I read that ClassDefNotFoundError is caused because at compile time the librairies are found, but they are not linked into the apk, so they can't be found at runtime.
How can I link the external jars in the apk please ?
The compilation process is ok, and after aligning the apk, it fails at runtime with ClassDefNotFoundError acra.ACRA
There is no acra.ACRA class in ACRA, at least not in the current edition. It's org.acra.ACRA.
My jars are in the libs folder at the root of the project. And I sort of understood this would cause ant to link them into the apk. But it doesn't.
Yes, it does. Then ProGuard is removing them, unless you teach ProGuard not to.
I'm having this problem since I installed the new SDKs. I've read about this happening when I try to link the same class to the build twice.
But here is the peculiar thing about it:
I have an Android library project that includes a class folder on the build path.
I have this library project included in one of my regular Android projects.
I have to include the class folder in this regular project as well to make it build.
This when the error occurs.
But when I do either of the following:
Remove the class folder from the library project: The library project won't build, so the regular project won't either.
Remove the class folder from the regular project: The library project builds, but the regular project won't because it misses the class files (?!).
I seem to be stuck in some unsolvable paradigm here.
Maybe there are build rules to circumvent this?
Any help would be greatly appreciated!
Apparently the way Android library projects are linked has changed.
Before, the library's source folder would be linked to the build path.
With the new solution the library is apparently built to a jar file in its own 'bin' folder.
This is then linked as an external jar to the build path of the project using the library.
To make the conflict dissappear, do two things:
Remove the source folder link in Project properties->Java Build Path->Source
Clean the project. Perhaps clear your projects 'bin' folder manually.
Now it should work again! :)
I maintain an Android app and am not using Eclipse. I am not using Eclipse. I am using ant and build.xml and build.properties.
I have places my .jar file into the libs/ directory. My code compiles just dandy. But when I run it on the emulator, the output APK does not include the .jar, so I get a runtime stacktrace:
ERROR/AndroidRuntime(470): java.lang.NoClassDefFoundError: com.google.ads.AdView
my build.properties looks like this:
jar.libs.dir=libs
And the libs/ directory contains my .jar file.
What needs to be in build.xml so that the external .jar file is included in the APK?
Edit: In theory this answer should work, but it doesn't for me. Is it out of date? What gives? How to add external jar libraries to an android project from the command line
I just came over a similar problem and noticed that libraries should not be placed in "myprojectdir\lib". When I moved them to "myprojectdir\libs" everything started to work.
It turns out that I needed to upgrade the version of ant I was using to 1.8. During the compile process, I had been getting this error message:
Warning: Reference out.dex.jar.input.ref has not been set at runtime,
but was found duringbuild file parsing, attempting to resolve. Future
versions of Ant may support referencing ids defined in non-executed
targets.
I googled it, and found that I needed to upgrade Ant, and now I don't get this warning, and my application does not force close.
What needs to be in build.xml so that the external .jar file is included in the APK?
Just putting it in libs/ is sufficient.
my build.properties looks like this:
That line should not be necessary. It does not appear in my build.properties files that build successfully with JAR files.
If you use dexdump -f classes.dex from your project's bin/ directory, you will be able to determine whether com.google.ads.AdView made it in there. If it did not, then something is strange with your build scripts. If it did, then perhaps there is a dependent JAR that you are missing (though I would expect a VerifyError in that case).
You use 3rd party library, but you seem didn't run DX on it. Make sure that not only your code processed by DX tool (I assume Ant does it), but also all 3rd party libraries you use. You can look in 7Bee script I use to convert web applications to Android davlik format, so it can work for you too. You can find more about the script on Atjeews page.
Solution:
right click on the project in project tree and select Project
properties
select Java Build Path
select TAB Order
and Export
check GoogleAdMobAdsSdk-4.0.4.jar (or your
version SDK)
press OK
clean project by menu Project
-> Clean
rebuild project (Project – Build Automatically)