I am developing an app that uses google maps. The app works fine up until I Export the signed app package .After the code has been obfuscated the maps are no longer loaded. I am pretty new to ProGuard,I've tried modifying proguard.cfg but soo far nothing has worked.
Here are some of the different things that i've tried:
-libraryjars C:/Program Files/Android/android-sdk/add-ons/addon-google_apis-google_inc_-10/libs/maps.jar
-keep class android.location.** { *; }
-keepnames class com.google.android.maps.** {*;}
-keep public class com.google.android.maps.** {*;}
-dontwarn com.google.android.maps.GeoPoint
-dontwarn com.google.android.maps.MapActivity
-dontwarn com.google.android.maps.MapView
-dontwarn com.google.android.maps.MapController
-dontwarn com.google.android.maps.Overlay
Thanks
Edit: For Google Maps For Android V2 Specifically:
Just in case anyone sees this and has a similar issue - I was getting a Parcelable RuntimeException when I tried to view a second map (as in, Activity A had a map instance, then moving to Activity B, another instance with different params), pointing to what i was assuming was an obfuscated class name in the google package.
after i added
-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }
to my proguard-project.txt everything seemed to keep working as normal
It is most likely issue with the Maps API Key. You should generate the Key with the signature used while exporting the app and use it in your map view.
Its unlikely that Obfuscation using ProGuard will affect the map rendering.
It might help:
-optimizations !code/simplification/variable
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Fragment
-keep public class * extends android.support.v4.app.Fragment
# The Maps API uses custom Parcelables.
# Use this rule (which is slightly broader than the standard recommended one)
# to avoid obfuscating them.
-keepclassmembers class * implements android.os.Parcelable {
static *** CREATOR;
}
# The Maps API uses serialization.
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
Source:
https://github.com/googlemaps/android-samples/blob/master/ApiDemos/app/proguard-rules.pro
I've had a similar issue using the Google Maps Roads API - it didn't work in obfuscated code. Turns out, the API library uses reflection under the hood, so the solution was to add
-keep class com.google.maps.** { *; }
to proguard-rules.pro.
(Adding this answer here specifically, because this question came up as the most related when I was searching for a solution to my issue, and finding the answer here would've saved me a couple hours of further searching.)
this is better
-keep class * implements com.google.android.gms.maps { *; }
-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }
Related
I am not able to generate the apk with proguard enabled after adding glide v4 library.
I have added the below lines in proguard-rules
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
It's showing the below error while building.
Warning:com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool:
can't find referenced field 'android.graphics.Bitmap$Config HARDWARE'
in library class android.graphics.Bitmap$Config
It's save to ignore these warning using:
-dontwarn com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool
-dontwarn com.bumptech.glide.load.resource.bitmap.Downsampler
-dontwarn com.bumptech.glide.load.resource.bitmap.HardwareConfigState
See this post
Proguard
If you use proguard, you may need to add the following lines to your proguard.cfg:
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
If you're targeting any API level less than Android API 27, also include:
-dontwarn com.bumptech.glide.load.resource.bitmap.VideoDecoder
VideoDecoder uses API 27 APIs which may cause proguard warnings even though the newer APIs won’t be called on devices with older versions of Android.
I assume you take your proguard rules from this glide page but it is miswritten. Replace below line
-keep public class * extends com.bumptech.glide.AppGlideModule
with this:
-keep public class * extends com.bumptech.glide.module.AppGlideModule
as you see, module package is missing. It is also properly documented on README page. You can also check your AppGlideModule class path from External Libraries.
You can as well increase your compileSdkVersion to 26. This takes care of the new features that Glide v4 uses.
I am trying to add custom Proguard rules for my app, but I am not sure into which file I should add those custom rules. I know of three files
1)Android/sdk/tools/proguard/proguard-android.txt
2)Android/sdk/tools/proguard/proguard-project.txt
3)Project --> app --> proguard-rules.pro
First of all you will use the
3)Project --> app --> proguard-rules.pro
and
few generic custom rules which are safe to apply on app and wouldn't
hinder the functioning of it
depends on the code in your app but if you will set minifyEnabled to true(which is recommended) this could lead to a lot of issues which can be solved through proguard rules file.
This is my proguard file for one of my projects where I'm using Fabric, httpApacheClient, shareActionProvider and some other libraries that needs specific rules for proguard.
# This will ignore warnings for missing translations and some other wanrinings
-ignorewarnings
# Keeping line numbers for easy error tracking :
-keepattributes SourceFile,LineNumberTable
# Support ShareActionProvider will not work without this line :
-keep class android.support.v7.widget.ShareActionProvider { *; }
# Flurry Crashlytics
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int); }
# Preserve Flurry mediation classes for DFP/AdMob Ads keep public class com.google.ads.mediation.flurry.**
# Google Play Services library
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents(); }
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL; }
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *; }
-keepnames class * implements android.os.Parcelable { public static final ** CREATOR;
}
-keepattributes InnerClasses, EnclosingMethod
-keep class com.ironsource.mobilcore.**{ *; }
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn android.app.Notification
-keep class com.dianxinos.DXStatService.stat.TokenManager {
public static java.lang.String getToken(android.content.Context);
}
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.app.Activity
-keep public class * extends android.content.ContentProvider
And almost you will find related proguard settings in the documentation of any external library you use.
in
3)Project --> app --> proguard-rules.pro
There are not generic proguard rules. All those generic ones already included with SDK, It depends on what features and libraries are you using in your project. Also there is no safeway of doing it. You have to apply rules and test app -> fix any issues then repeat same process.
I'm trying to configure Proguard, but I can't manage to get it working.
This is the error:
I've tried things like:
-keep class com.android.auth.TwitterHandle.** { *; }
-keep class oauth.** { *; }
Without any luck.
Anyways, I don't really think ignoring is the answer. Because that might mean something is broken.
Any tips?
Thanks!
The warnings indicate that the AndroidQuery library depends on the OAuth library. Apparently, you're using the former library in your project, but the latter library is missing. You could add the missing library, but if your application is working fine without it in debug mode, you can just tell ProGuard to ignore the missing dependency. In this case:
-dontwarn com.androidquery.auth.**
or, to the same effect:
-dontwarn oauth.signpost.**
See the ProGuard manual > Troubleshooting > Warning: can't find referenced class
(I am the developer of ProGuard)
Add these lines to your proguard file.
-dontwarn oauth.**
-dontwarn com.android.auth.TwitterHandle.**
-keep class oauth.** { *; }
-keep class com.android.auth.TwitterHandle.** { *; }
Edit:
Anyways, I don't really think ignoring is the answer. Because that
might mean something is broken.
If you want to use Proguard and you are having some errors such as class not found, then you must disable/ignore their obfuscation. Because Proguard renames names, fields and methods of classes while obfuscating. This becomes a big problem if reflection is used for that classes. So you have to say proguard to ignore(not obfuscate) some classes to prevent this problem.
Please try this post https://stackoverflow.com/a/15477898/1665964
Insert to skip obfuscated in ProGuard your libs, jars, Classes and Subclasses with this example
-optimizationpasses 5
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-repackageclasses ''
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.MapActivity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-libraryjars libs/commons-io-2.2.jar
-libraryjars libs/gson-2.2.2.jar
-keep public class org.apache.commons.io.**
-keep public class com.google.gson.**
-keep public class com.google.gson.** {public private protected *;}
##---------------Begin: proguard configuration for Gson ----------
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.mypackage.ActivityMonitor.ClassMultiPoints.** { *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints { public protected *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints$ClassPoints { public protected *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints$ClassPoints$ClassPoint { public protected *; }
##---------------End: proguard configuration for Gson ----------
The reason for error must be that you might be using an external jar file (in libs folder).
If this is the case, adding the following line before -keep class ... lines should solve your problem.
-libraryjars libs/<jar_filename>
If u are unfamiliar with proguard cmd tool then you can try proguard gui located at tools/proguard/lib/proguardgui of your android SDK folder.
open proguardgui and load your configuration file.
then in Input / output section add your input and output jar as well as add your android lib used in your project.
***** your main problem is that you havent added your library (Aquery.jar and others) jar that is used in your project , so that proguard can't find the required Classes.***
I developed android app and I used admob sdk 6.2.1 for showing ads, and when I tested the app on my real device and on the emulator,ads are shown.
but when I apply pro guard to my app and test it on my device(I tested it on another devices also) ads are not shown up, any help please!
Add this to your proguard:
-keep class com.google.ads.** # Don't proguard AdMob classes
-dontwarn com.google.ads.** # Temporary workaround for v6.2.1. It gives a warning that you can ignore
EDIT 2020:
For some time now, the Google Mobile Ads SDK has distributed its own proguard rules that get manifest merged into your app, so you don't need to add anything yourselves. The merged rules also keep around methods from third-party mediation adapters that are needed to make mediation work.
From the docs:
To safely use ProGuard with Google Mobile Ads, add the following to your ProGuard config:
-keep public class com.google.android.gms.ads.** {
public *;
}
-keep public class com.google.ads.** {
public *;
}
This will prevent all public methods on public classes from being obfuscated.
If you use AdMob Mediation with other ad networks, you should keep public methods from public classes for each SDK and adapter library as well.
Proguard Rules for Admob in Android
-keep public class com.google.android.gms.ads.**{
public *;
}
# For old ads classes
-keep public class com.google.ads.**{
public *;
}
# For mediation
-keepattributes *Annotation*
# Other required classes for Google Play Services
# Read more at http://developer.android.com/google/play-services/setup.html
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
I am building an application with android platform. Will like to design a server side akka application that will provide services in a distributed manner to the android application. Both systems are designed as separate applications. Will it be possible to connect the akka remote server with the android application. Please help me out cos I am new to both akka and android.
You can do this, but you will suffer.
You must somehow be able to access the class definitions for akka-remote and dependencies (netty, scala) from your android app. This can be problematic, since the sum of dependencies has more than 65536 methods which is Dalviks cap. (That is - your classes.dex file inside the apk cannot have more method definitions than 65536).
AFAIK, there's three main approaches:
Split up the dependencies into separate apklibs and make your apk depend on these.
I can't really recommend this since I haven't tried it.
Split up the dependencies into separate classes.dex files that you load programmatically from your app.
Probably doable. Never tried it.
Run proguard before packing your classes.dex
You'll have to battle with proguard to get the config right, and you may get strange runtime failures. My config is posted below.
Once you get akka-remote up and running on your android device you can connect to the server like in the examples in the docs. However, keep in mind that:
The IP of your Android device may or may not be available at boot time, so you may wan't to keep that part of your akka config dynamic (haven't done this myself).
The IP of your Android device may not be reachable from the server. So if you get into a state where the server needs to call the client back, it will never succeed.
My proguard.cfg (some lines are not needed - haven't bothered figure out which ones):
-dontoptimize
#-optimizationpasses 2
-dontobfuscate
-dontpreverify
-dontskipnonpubliclibraryclassmembers
-dontskipnonpubliclibraryclasses
-dontnote **
-verbose
-keep class com.typesafe.config.Config { *; }
-keep class com.typesafe.config.ConfigFactory { *; }
-keep class org.slf4j.Logger { *; }
-keep class org.slf4j.LoggerFactory { *; }
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#Scala
-dontwarn scala.**
-keepclassmembers class * {
** MODULE$;
}
-keep class scala.Option
-keep class scala.Function1
-keep class scala.PartialFunction
#https://issues.scala-lang.org/browse/SI-5397
-keep class scala.collection.SeqLike {
public protected *;
}
-keep class scala.Tuple*
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
-keep class * implements org.xml.sax.EntityResolver
-keepclassmembers class * {
** MODULE$;
}
-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinPool { *; }
-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinWorkerThread {
int base;
int sp;
int runState;
}
-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinTask {
int status;
}
-keepclassmembernames class scala.concurrent.forkjoin.LinkedTransferQueue { *; }
#Akka
-dontwarn org.jboss.netty.logging.**
-dontwarn org.osgi.**
-dontwarn javax.servlet.**
#-dontwarn org.jboss.netty.channel.socket.http.**
## Unsafe is there at runtime
-dontwarn sun.misc.Unsafe
-keep class sun.misc.Unsafe{
*;
}
-keep class akka.** { *; }
-keep class com.google.protobuf.GeneratedMessage {
*;
}
-keep class org.javatuples.** { *; }
-keep class org.jboss.**
-dontwarn org.jboss.netty.handler.codec.marshalling.**
-dontwarn org.jboss.netty.channel.socket.nio.**
-dontwarn org.jboss.netty.handler.codec.compression.JdkZlibEncoder
-dontwarn org.jboss.netty.handler.codec.spdy.SpdyHeaderBlockZlibCompressor
-dontwarn org.jboss.netty.channel.socket.http.HttpTunnelingServlet
-dontwarn org.jboss.modules.**
-dontwarn __redirected.**
-dontwarn org.slf4j.LoggerFactory
-dontwarn org.slf4j.MarkerFactory
-dontwarn org.slf4j.MDC
-dontwarn org.slf4j.impl.AndroidLogger
-dontwarn org.slf4j.impl.AndroidLoggerFactory
Good luck.
I'm not sure if you were thinking of using the Akka remoting protocol, but if it were me, I would consider looking into the excellent HTTP+REST library Spray (http://spray.io/). I've played around with this library and it is very slick. It is well integrated with Akka and would allow you to provide REST APIs for your services. As a bonus, going REST also allows you to have services that will easily integrate with things other than your Android frontend.
I've included a couple of links as a starting point. The Google 2010 I/O talk on writing REST clients for Android apps is especially interesting:
http://www.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html
http://www.techrepublic.com/blog/app-builder/calling-restful-services-from-your-android-app/1076