Tuesday, January 25, 2011

why wont google maps work after resigning or recompiling?

this is because access to google's stuff requires an api key, stored in xml as a resource or perhaps in code, that is linked with the certificate of the app. if you modified and resigned it, the certificate is different and will not match the api key. you will have to get a valid key for the signature you are using.

you should already have your own certificate you sign everything with. this way if you release an updated version of the app, users of your previous modified version can update without needing to uninstall the old one first. if you don't already have your own certificate, follow the directions here: Signing Your Applications | Android Developers. you will need to use keytool and examples are given in the link.

once you're done or if you already have your own certificate, follow the instructions here: Obtaining a Maps API Key - Google Projects for Android.

when finished with that, and you have your own api key, decompile your apk with apktool so you can modify resources. you are looking for an xml file with a string like:
android:apiKey="3BCknOWFD_vyechU238a1f9YOWyYP2Z91CEfQWw"

or if it is created dynamically in code, you will see the initialization of a mapview object. the constructor takes a string as the second parameter which is the api key. here's an example:
# replace p2 with our api key here:
const-string p2, "3BCknOWFD_vyechU238a1f9YOWyYP2Z91CEfQWw"

# create the mapview object with our modified api key
# this line should already be here and doesn't need to be changed
invoke-direct {p0, p1, p2}, Lcom/google/android/maps/MapView;-><init>(Landroid/content/Context;Ljava/lang/String;)V

4 comments :

  1. Hi,
    Firstly, thanks for your great educational blog.
    I wonder if Youtube application have a similar issue when decompiling. I tried to decompile and compile without a modification but when I try to start app, force crashes immediately .

    ReplyDelete
  2. you're welcome. what did you use to decompile? always, always check logs if you get a force close. depending on the decompiler you used, post what you did, what happened and the logs as a bug report.

    ReplyDelete
  3. I've used apktool (apktool d ) as always I do. I checked logs and logcat during compiling (again, apktool), installation and starting the application. No error raised during compiling. But when i tried to start application on my phone, saw an error in logcat:

    E/dalvikvm(29116): Could not find class 'dI', referenced from method dT.b...

    Well can't check the exact error right now. But I'll post a full log soon.

    ReplyDelete
  4. yes thats true it took me many days to understand this

    actually api key is present in androidmanifest.xml

    just go to google console put the package name and sha1 of you signature and get api key and replace with new one in android manifest and resign

    thats same i did with app flightradar24 pro

    http://jasi2169.blogspot.in/2014/11/flightradar24-flight-track-v60-premium.html#more

    the thing i got to know later was well written by lohan years back wow

    i miss that tool of signature invoke lohan :( crying crying :( i know that is private plz add me in exception :P plz ;)

    ReplyDelete

Do NOT post about or link to specific apps!