Proguard folder empty - android

I am using Eclipse to build my Android Application. When I export the project as an Android Application I can use my keystore and key to sign the apk just fine. Before exporting I also added the Proguard config location to the properties file, I also changed my Android SDK file path to one without spaces, and I have debuggable set to false in my manifest.
With all of those done, the proguard folder in my project that is created does not contain any files and the Android documentation claims it will contain several.
http://developer.android.com/guide/developing/tools/proguard.html
What have I missed?

Stupid error on my part. It looked like it was succeeding because it was. Its just the proguard files weren't imported into eclipse so they didn't show up in package explorer. Manually entering workspace I found them.
That is indeed a little embarrassing. Oh well.

Related

Difficulties setting up Gradle to send ProGuard mapping files to Firebase

I am trying to follow this documentation tutorial by Firebase to setup Android Studio to automatically send my ProGuard mappings file when building a release APK for my Android application.
However, I couldn't seem to understand steps 4 and 5 in the "Uploading ProGuard mapping files with Gradle" part, mainly because I didn't find any gradle.properties file in my project root or home path and because I wish to automate the execution of the app:firebaseUploadReleaseProguardMapping task in Android Studio, which I don't know how to do.
This is the contents of the gradle.properties file I've created in my project root directory:
FirebaseServiceAccountFilePath = /app/firebase-crash-reporting.json
The firebase-crash-reporting.json file is my Firebase crash reporting private key. My mappings file is generated in the /app/build/outputs/mapping/release/ directory, if that helps.
Please assist me in completing those 2 steps and automatizing the process in Android Studio.
Just add
afterEvaluate {
assembleRelease.doLast {
firebaseUploadReleaseProguardMapping.execute()
}
}
In the android section of build.gradle file.
This will automatically upload the ProGuard mappings file to Firebase as well as run/deploy the APK to the device using ADB.
gradle.properties is owned and managed completely by you. You have to create it if it doesn't already exist. This means you should probably read the Gradle documentation on it to best understand how it provides properties to your builds, and which location is best for your properties.
You are not even obliged to use gradle.properties. You can also specify all the properties for the Crash Reporting plugin via the command line.
When you specify a path for the service account file, you should specify the full, unambiguous path to the file. In your example, it looks like you're assuming that it will look under the app directory in your project. If you want to do that, you still have to give the full path to the file.

Eclipse: Override library path defined in project.properties

I'm using ActionBarSherlock as a library. We haven't included ABS into our repository so everyone participating our project must download and install it separately. ActioBarSherlock is an Android library project and I have got it running by opening it and my project in the same Eclipse's workspace (neither of those are copied into workspace, they both exists in another folder) and adding it into my project.properties by following this:
Referencing a library project.
That reference path is relative and since everyone might have ABS in different folder, we also have different paths in Eclipse's project.properties file as android.library.reference.1. Is there any way locally override that library path so that we can have project.properties in our repo but Eclipse will use locally some other path? Currently I have to manually fix that path after every time I pull from our repo because of different paths.
There exists other *.properties files but Eclipse ignores them:
local.properties
Customizable computer-specific properties for the build system. If you use Ant to build the project, this contains the path to the SDK installation. Because the content of the file is specific to the local installation of the SDK, the local.properties should not be maintained in a source revision control system. If you use Eclipse, this file is not used.
ant.properties
Customizable properties for the build system. You can edit this file to override default build settings used by Ant and also provide the location of your keystore and key alias so that the build tools can sign your application when building in release mode. This file is integral to the project, so maintain it in a source revision control system. If you use Eclipse, this file is not used.
Just have each person put it in projectroot/libs. The newer (ADT 17 and above, IIRC) versions of the ADT will automatically pick it up and compile it into your app. Note that the folder is libs, with an s, and not lib. Using /lib won't work.
Options:
project.properties: You could create a link in every users home folder, libs and have the path in the project.properties refer to ~/libs
Using a common library:
Create a library project called "common". In settings, have it export the jar. In your Android application, import the jar.
Personally I think configuring with maven would be best but the 2nd option was quickest.
What about if you ignore the project.properties in your repo? That way each user can keep their own and you won't need to override it all the time. I don't think you can override that locally.
Another option to simplify things is you can export the project as a JAR file instead of referencing it as a library project. If you don't need to modify ABS code you can right click the project -> java -> jar file and all the developers can keep that in the same place for the sake of simplicity.
Edit: This question is no longer needed for our project since we moved from Eclipse to Android Studio and Gradle build system. Eclipse with Maven should have worked too, as #bgs suggested.
Our previous approach:
Still looking for better alternative but so far we ended up keeping project.properties in our repo. project.properties does not get overridden if there is no changes to it when pulling. We also suggest in our README that users add this
[alias]
commit = commit -X project.properties
to their .hg/hgrc configuration file to prevent accidentally commiting changes of that file.
This method has at least one drawback: When merging, you might get error like this abort: cannot partially commit a merge (do not specify files or patterns) even when you commit your merge with hg commit -m 'merge'. If this happens, disable that alias temporarily.

Obfuscated code

I was asked to crate a simple app for android. The first one in fact that I'll be paid for, so I really don't want to screw it up :). One of the requirements was that the code must be obfuscated.
I learned the general idea of obfuscating, but I don't want to make any silly mistakes.
What precisely do I have to do to make the code obfuscated? Does exporting it as release do the job, or some other steps are required? Any remarks are also appreciated.
PS. I'm using Eclipse if it matters.
EDIT
From the article suggested in the anwsers:
To enable ProGuard so that it runs as part of an Ant or Eclipse build,
set the proguard.config property in the
/project.properties file. The path can be an absolute
path or a path relative to the project's root.
If you left the proguard.cfg file in its default location (the
project's root directory), you can specify its location like this:
proguard.config=proguard.cfg
I indeed have the project.properties file in my project's dir. But I don't have the proguard.cfg file. Instead I have the proguard-project.txt file. I guess it's a replacement.
project.properties:
This file is automatically generated by Android Tools.
Do not modify this file -- YOUR CHANGES WILL BE ERASED!
This file must be checked in Version Control Systems.
To customize properties used by the Ant build system edit
"ant.properties", and override values to adapt the script to your
project structure.
To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt
Project target.
target=android-7
Originally everything but the last line is commented out.
In proguard-project.txt everything is commented out.
I guess I'm lost here, so I'd be very thankful If somebody could tell me step by step what I am supposed to do and also how to check if it actually works.
The article on the official dev site is out of date. Starting with SDK Tools r17 they changed the way the ProGuard configuration works. Basically they split what used to be proguard.cfg into two files (and also simply made them .txt files): proguard-android.txt and proguard-project.txt. proguard-android.txt resides in your {SDK dir}\tools\proguard directory and proguard-project.txt is in each of your project directories.
They split the file so that general configuration/flags that the Android team deems pretty standard will be in the proguard-android.txt file and can be updated (basically silently) with each SDK Tools revision. And then any developer/project specific flags, the developer can add to the proguard-project.txt file.
This is why you noticed everything in your proguard-project.txt file was commented out, because in general most people don't have any project specific needs, they just want to run ProGuard with standard settings and be done with it.
For reference (a very good explanation): http://tools.android.com/recent/proguardimprovements
Step-by-Step (day by day :P)
(Using Eclipse IDE) To enable ProGuard and it's shrinking and obfuscation using only the default settings:
First update your SDK Tools to newest (r19 at time of writing)
In project.properties uncomment the line that says:
proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt
If you created the project before r17 then you might not see the same things. If that's the case I suggest you create a new dummy project (after updating SDK Tools) and just copy over the proguard-project.txt and project.properties files.
That's it! ProGuard will now be enabled and it will run, but only on release builds (when you use Android Tools and export a signed/unsigned apk).
When you make a release build you'll notice that a new ProGuard folder will be created in your project folder. Within this folder you find four files with stuff like what classes/methods were kept or removed. Also note that when you obfuscate, you'll also obfuscate your stacktraces in the event of errors.
Edit: (9/4/12) Just wanted to update this answer to reflect changes in Tools r20.
The Android team has now added one additional proguard configuration file. It is proguard-android-optimize.txt and it also resides in the {SDK dir}\tools\proguard directory. This file is the same as the original proguard-android.txt config file, except it has proguard optimization turned on.
This additional file was added for convenience for those who wanted to turn on optimizations (maybe so they can do stuff like strip out Log calls, which requires optimizations be turned on). Now you can simply point to this file instead in your project.properties file like so:
proguard.config=${sdk.dir}\tools\proguard\proguard-android-optimize.txt:proguard-project.txt
As before, don't try to alter any of the proguard-android... config files. Any project specific flags should go in the proguard-project.txt file in your project folder.

Building android project with ant

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.

How to include JAR in APK without Eclipse?

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)

Categories

Resources