I was testing this morning, and the app went ahead an crashed on a leaked window, as follows.
/LicenseChecker(15862): Calling checkLicense on service for com.jlptquiz.app
I/LicenseChecker(15862): Start monitoring timeout.
E/WindowManager(15862): Activity com.jlptquiz.app.StartActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4062c338 that was originally added here
E/WindowManager(15862): android.view.WindowLeaked: Activity com.jlptquiz.app.StartActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4062c338 that was originally added here
E/WindowManager(15862): at android.view.ViewRoot.
E/WindowManager(15862): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
E/WindowManager(15862): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/WindowManager(15862): at android.view.Window$LocalWindowManager.addView(Window.java:424)
E/WindowManager(15862): at android.app.Dialog.show(Dialog.java:241)
E/WindowManager(15862): at android.app.ProgressDialog.show(ProgressDialog.java:107)
E/WindowManager(15862): at android.app.ProgressDialog.show(ProgressDialog.java:90)
E/WindowManager(15862): at com.jlptquiz.app.ValidateLicense.valdidateLicense(ValidateLicense.java:62)
E/WindowManager(15862): at com.jlptquiz.app.StartActivity.validateLicense(StartActivity.java:306)
E/WindowManager(15862): at com.jlptquiz.app.StartActivity.onCreate(StartActivity.java:85)
E/WindowManager(15862): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/WindowManager(15862): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
E/WindowManager(15862): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/WindowManager(15862): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2832)
E/WindowManager(15862): at android.app.ActivityThread.access$1600(ActivityThread.java:117)
E
The problem is that I was checking a slightly dated version of the code, since I haven't added the new version yet. But, the problem is that this looks like the same problem I had a couple of days ago, and thought I had solved.
/LicenseChecker(15862): Calling checkLicense on service for com.jlptquiz.app
I/LicenseChecker(15862): Start monitoring timeout.
So, I can get rid of the dialog, which would solve the problem. But the dialog is useful in the case where you're connected, but can't get through to the server, i.e. the Panera situation before you've gone enabled yourself through their gateway.
Another option would be to just jigger the code to run it even though it's getting a market not managed error.
The third option is to just add the app in draft mode, which I need to do anyway. I might as well go with the third option.
Ok, so to do that, I think I need to generate the apk and upload it. Let's find the Android Develop Account profile page. I should have that memorize...
Here its, from http://gettingintomobile.blogspot.com/2011/07/android-licensing-completion.html
https://market.android.com/publish/editProfile
Right, and there's an upload application button right there.
Ok, so, now just to prepare the apk. We explored that process in this post:
http://gettingintomobile.blogspot.com/2011/07/android-licensing-completion.html, entitled "Android licensing - progress!"
So, let's run the script...did I name my project what I want to call the apk? How about "JlptQuiz4Full".
Actually this should be an Ant or a Maven file. We'll get to that - maybe.
Let's run it...
mysystem$ ./adb_install JlptQuiz4Full
Uninstalling JlptQuiz4Full....
copying from project's bin to its deploy direcotory...
cp: directory ../JlptQuiz4Full/deploy does not exist
signing jar...
Enter Passphrase for keystore:
jarsigner: unable to open jar file: ../JlptQuiz4Full/deploy/JlptQuiz4Full.apk
Checking if APK is verified...
jarsigner: java.util.zip.ZipException: error in opening zip file
removing old temp file..
running zipalign to temp file..
Unable to open '../JlptQuiz4Full/deploy/JlptQuiz4Full.apk' as zip archive
moving temp back to original deploy apk
mv: rename temp to ../JlptQuiz4Full/deploy/JlptQuiz4Full.apk: No such file or directory
Mark-Donaghues-MacBook-Pro:androidkeys markdonaghue
Oh, it's looking for the file in the deploy directory, but there isn't one. Well, let's toss it into the script so I don't have create it manually...I really should use maven.
Here's a link on how to do it in shell:
http://www.cyberciti.biz/tips/find-out-if-directory-exists.html
Find out if /tmp directory exists or not
So, let's try this:
echo "creating deploy directory"
if [ ! -d ../$1/deploy/ ]
then
mkdir ../$1/deploy/
fi
echo "copying from project's bin to its deploy directory..."
cp ../$1/bin/$1.apk ../$1/deploy/
Ok, let's try the new one:
mypromt$./adb_install JlptQuiz4Full
Uninstalling JlptQuiz4Full....
creating deploy directory
copying from project's bin to its deploy direcotory...
signing jar...
Enter Passphrase for keystore:
jarsigner: unable to sign jar: java.util.zip.ZipException: invalid entry compressed size (expected 2021 but got 2050 bytes)
Checking if APK is verified...
jar verified.
Warning:
This jar contains entries whose signer certificate will expire within six months.
Re-run with the -verbose and -certs options for more details.
removing old temp file..
running zipalign to temp file..
moving temp back to original deploy apk
That looks a little better. Here's the updated script:
#!/bin/bash
#!/bin/bash
############################################################################
#
# adb_install
#
# Install script for android apk file.
#
# The apk file generated is deployable to the Android App store
#
# The assumption of the script is that the apk name (less ".apk" corresponds
# to the project name. Also, it must be run from a directory at the same level
# as the project.
#
# The paramater to the script should be the project name
#
# The script first copies the apk from the project's bin directory to its deploy directory
#
# It then signs the apk file
#
# To zip align it, it deletes any existing "temp" file, zipaligns the deploy apk file to temp
# deletes the origin deploy apk, and move the aligned temp to the deploy apk.
#
# Mark Dongaghue
# KanjiSoft Systems
#
#############################################################################
echo "Uninstalling $1...."
#adb uninstall "$1.apk"
echo "creating deploy directory"
if [ ! -d ../$1/deploy/ ]
then
mkdir ../$1/deploy/
fi
echo "copying from project's bin to its deploy direcotory..."
cp ../$1/bin/$1.apk ../$1/deploy/
echo "signing jar..."
jarsigner -verbose -keystore my-release-key.keystore "../$1/deploy/$1.apk" alias_name
echo "Checking if APK is verified..."
jarsigner -verify "../$1/deploy/$1.apk"
# renames to temp
echo "removing old temp file.."
rm -f temp
echo "running zipalign to temp file.."
zipalign -f 4 "../$1/deploy/$1.apk" temp
#echo "removing original deploy apk file.."
#rm -f "../$1/deploy/$1.apk"
echo "moving temp back to original deploy apk"
mv temp "../$1/deploy/$1.apk"
#adb install "../$1/deploy/$1.apk"
Ok, now, let's upload the apk.
Oops...got this lovely error message.
"Market does not accept apks signed with the debug certificate. Create a new certificate that is valid for at least 50 years.
Market requires that the certificate used to sign the apk be valid until at least October 22, 2033. Create a new certificate."
Why didn't I get that before?
Let's review the guidelines..
http://developer.android.com/guide/publishing/publishing.html
If you plan to publish your application on Android Market, you must make sure that it meets the requirements listed below, which are enforced by the Market server when you upload the application.
Requirements enforced by the Android Market server:
Your application must be signed with a cryptographic private key whose validity period ends after 22 October 2033.
Your application must define both an android:versionCode and an android:versionName attribute in the
Your application must define both an android:icon and an android:label attribute in the
Do I have a different key? It looks like I have only one keystore.
Let's check out this, from the "preparing your app", "obtaining a suitable cryptographic key", which links to this:
http://developer.android.com/guide/publishing/app-signing.html#cert
Well, I must be trying to upload the wrong apk,
Ah, going back, I hadn't successfully signed it. One day, this process will go smoothly.
Why doesn't just using the straight apk to run the script on work?
Also, why this message on the install: [2011-08-01 10:18:57 - AndroidLicensingProject] Could not find AndroidLicensingProject.apk!
Well, ok. It seems when I do the export, I'm singing the file right there. I just notices that it said the certificate expires in 2038 or something. But why does it sign the file when I don't do that, or it seems to?
Ah, here we go,
http://developer.android.com/guide/publishing/app-signing.html
In order to release your application to users, you must compile it in release mode. In release mode, the compiled application is not signed by default and you will need to sign it with your private key.
With Eclipse
To export an unsigned .apk from Eclipse, right-click the project in the Package Explorer and select Android Tools > Export Unsigned Application Package. Then specify the file location for the unsigned .apk. (Alternatively, open your AndroidManifest.xml file in Eclipse, open the Overview tab, and click Export an unsigned .apk.)
So, am I compiling in debug mode? I didn't think I was, it's not in the manifest.
Ok, here's some insight:
http://developer.android.com/guide/publishing/app-signing.html#debugmode
Eclipse Users
If you are developing in Eclipse/ADT (and have set up Keytool as described above in Basic Setup for Signing), signing in debug mode is enabled by default. When you run or debug your application, ADT signs the .apk with the debug certificate, runs zipalign on the package, then installs it on the selected emulator or connected device. No specific action on your part is needed, provided ADT has access to Keytool.
So, I guess I need to disable debug mode if I want to use the default apk.
Here's another way:
"I found another way to remove the signature. An APK file is just a zip file. So un-zip the APK file, them remove the META-INF folder and then rezip it. Now if you use jarsigner to sign the APK file it all works fine."
Am I fighting city hall on this? Well, let's just do the export unsigned apk option.
To export an unsigned .apk from Eclipse, right-click the project in the Package Explorer and select Android Tools > Export Unsigned Application Package. Then specify the file location for the unsigned .apk. (Alternatively, open your AndroidManifest.xml file in Eclipse, open the Overview tab, and click Export an unsigned .apk.)
Ok, now, I should be ok.
Whoah, look at this:
./adb_install JlptQuiz4Full
creating deploy directory
copying from project's bin to its deploy direcotory...
signing jar...
Enter Passphrase for keystore:
adding: META-INF/MANIFEST.MF
adding: META-INF/ALIAS_NA.SF
adding: META-INF/ALIAS_NA.RSA
signing: assets/epminbld.ttf
signing: res/anim/custom_anim.xml
signing: res/anim/fade_in.xml
signing: res/anim/fade_out.xml
signing: res/drawable/a.png
signing: res/drawable/all_was_darkness.png
signing: res/drawable/backgroundlistcell.xml
signing: res/drawable/btn_radio.xml
signing: res/drawable/btn_radio_off.png
signing: res/drawable/btn_radio_on.png
signing: res/drawable/custom_button_drawable.xml
signing: res/drawable/dialog_custom.png
signing: res/drawable/fragile_as_snow.png
signing: res/drawable/hanami_looking_at_cherries.png
signing: res/drawable/hilight_correct_selector.xml
signing: res/drawable/hilight_default_selector.xml
signing: res/drawable/hilight_gradient_correct_drawable.xml
signing: res/drawable/hilight_gradient_incorrect_drawable.xml
signing: res/drawable/hilight_no_gradient_correct_drawable.xml
signing: res/drawable/hilight_no_gradient_default_drawable.xml
signing: res/drawable/hilight_transparent_drawable.xml
signing: res/drawable/ic_icon.png
signing: res/drawable/idle_hours.png
signing: res/drawable/lin1.jpg
signing: res/drawable/listcell_enabled.xml
signing: res/drawable/listcell_pressed.xml
signing: res/drawable/looking_at_the_moon.png
signing: res/drawable/looking_at_the_moon_240.png
signing: res/drawable/plum_blossoms.png
signing: res/drawable/progress_correct_drawable.xml
signing: res/drawable/progress_horizontal_drawable.xml
signing: res/drawable/progress_incorrect_drawable.xml
signing: res/drawable/progress_timeout_drawable.xml
signing: res/drawable/progress_timeout_drawable_old.xml
signing: res/drawable/sei_shonagan_and_the_hell_screen.png
signing: res/drawable/snow_cranes.png
signing: res/drawable/snow_viewing.png
signing: res/drawable/tasacode_whose_sleeve.png
signing: res/drawable/the_abbot.png
signing: res/drawable/the_go_game.png
signing: res/drawable/the_third_princess.png
signing: res/drawable/ukifune_and_karou_at_uji.png
signing: res/drawable/ukiune_wandering.png
signing: res/drawable/wisteria.png
signing: res/drawable/yugao.png
signing: res/layout/main.xml
signing: res/layout/next_level.xml
signing: res/layout/question.xml
signing: res/layout/settings.xml
signing: res/layout/simple_list_item_single_choice_custom.xml
signing: res/layout/start_layout.xml
signing: res/layout/validation_activity.xml
signing: AndroidManifest.xml
signing: resources.arsc
signing: res/drawable-hdpi/icon.png
signing: res/drawable-ldpi/icon.png
signing: res/drawable-mdpi/icon.png
signing: classes.dex
Checking if APK is verified...
jar verified.
removing old temp file..
running zipalign to temp file..
moving temp back to original deploy apk
How about that?
Now, let's upload.
Ok, it's up there - but now I can't tell the difference between the two apps. There's no upload date, and I didn't fill in any of the details. I could just delete them both, but I'm not sure how that affects the licensing key.
Ok, it looks like there's only one Base64-encoded RSA public key. So, it's possible I'm not correctly specifying it anymore?
Whoa! To get rid of that "[2011-08-01 10:24:11 - AndroidLicensingProject] Could not find AndroidLicensingProject.apk!" message, I deleted it from the project / property / build path / projects - and now the project name is showing up as "AndroidLicensingProject". Huh?
I think yesterday we determined that the app label in the manifest was the label underneath the icon, and the app title was coming from app_name in strings.xml.
Yes, there it is in the AndroidLicensingProject's res/strings.xml:
Ah, I didn't put an app name in the new project! Why was it showing up correctly before? I must have deleted it since I last saw the page. Wait - this means it's passed the licensing test! Because now I'm seeing the start page, instead of the usual licensing error! So, just by virtue of adding that apk, the Licensing logic sees the package name - probably in the manifest - and makes it a managed application. Nice.
Actually, the app label might stay the same, actually default to the "core" app_label of Jlpt Quiz App. So, we'll just delete the licensing app_name string entry, and run it.
And there it is.
Ok, we've *finally* got the app uploaded, and successfully license-validated. We re-figured out that for the signed apk script to work, we need to go to Android Tools, export unsigned app in Eclipse and then run the script. We can delete the apps from the Google Marketplace and start adding the apps, this time with some detail specified. We know that as long as the apk is uploaded, even in draft form, it's managed under licensing validation.
Ok, let's get back to testing *current* code and see if we can recreate the Window leak issue.
No comments:
Post a Comment