[SB 2.20] APK corrupted *without* debugger enabled

Just starting out? Need help? Post your questions and find answers here.
bbanelli
Posts: 107
Joined: Mon Jul 13, 2015 7:40 am

[SB 2.20] APK corrupted *without* debugger enabled

Post by bbanelli »

Code: Select all

;Constant definitions
#ButtonWidth = 320
#ButtonHeight = 200

Enumeration hWnd
  #hWndMain
EndEnumeration

Enumeration hGadget
  #hGadget_Button_Main_Inventura_Nova
  #hGadget_Button_Main_Inventura_Nastavi
  #hGadget_Button_Main_Inventura_Izlist
EndEnumeration

If OpenWindow(#hWndMain, 0, 0, 0, 0, "", #PB_Window_Background)
  Define.i MainWindowWidth, MainWindowHeight
  MainWindowWidth = WindowWidth(#hWndMain)
  MainWindowHeight = WindowHeight(#hWndMain)
  ButtonGadget(#hGadget_Button_Main_Inventura_Nova, MainWindowWidth / 2 - (#ButtonWidth / 2), 10, #ButtonWidth, #ButtonHeight, "Nova inventura")
  ButtonGadget(#hGadget_Button_Main_Inventura_Nastavi, MainWindowWidth / 2 - (#ButtonWidth / 2), 20 + #ButtonHeight, #ButtonWidth, #ButtonHeight, "Nastavi inventuru")
  ButtonGadget(#hGadget_Button_Main_Inventura_Izlist, MainWindowWidth / 2 - (#ButtonWidth / 2), 30 + #ButtonHeight * 2, #ButtonWidth, #ButtonHeight, "Izlistaj inventuru")
EndIf
Image

When compiled WITHOUT debugging option checked, apk cannot be installed but reports being corrupted. Android 7.0 (vanilla), Motorola G5+.

Here's the error from adb:
adb wrote:Failed to install .\xxx.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Package /data/app/vmdl171308109.tmp/base.apk has no certificates at entry AndroidManifest.xml]
Solution (workaround?) for Windows:
1.) Go to your JDK installation folder -> bin (in my case C:\Program Files\Java\jdk1.8.0_144\bin) and run command

Code: Select all

keytool -genkeypair -v -keystore NAME.keystore -alias NAME -keyalg RSA -keysize 2048 -validity 10000
After that, you should get something like this:

Code: Select all

Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  YOUR NAME
What is the name of your organizational unit?
  [Unknown]:  YOUR NAME
What is the name of your organization?
  [Unknown]:  YOUR NAME
What is the name of your City or Locality?
  [Unknown]:  YOUR NAME
What is the name of your State or Province?
  [Unknown]:  YOUR NAME
What is the two-letter country code for this unit?
  [Unknown]:  YOUR NAME
Is CN=YOUR NAME, OU=YOUR NAME, O=YOUR NAME, L=YOUR NAME, ST=YOUR NAME, C=YOUR NAMEcorrect?
  [no]:  yes

Generating 2.048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10.000 days
        for: CN=YOUR NAME, OU=YOUR NAME, O=YOUR NAME, L=YOUR NAME, ST=YOUR NAME, C=YOUR NAME
Enter key password for <YOUR NAME>
        (RETURN if same as keystore password):
Re-enter new password:
[Storing NAME.keystore]
2.) Download http://dl-ssl.google.com/android/reposi ... indows.zip, extract, run android.bat and install Android SDK build-tools 25.0.3.
3.) Go to build-tools folder, copy your apk and rename it somehow, for example, YOURAPP_Unsigned.apk
4.) This might require repetition of step; run:

Code: Select all

zipalign.exe -f -v 4 YOURAPP_Unsigned.apk  YOURAPP.apk
If you get "Verification failed", run it again but on "new" apk (delete "unsigned" version and rename the new one, for example). You should get "Verification succesful" (yes, it is spelled wrong for some reason)
5.) Finally, copy that keystore from JDK folder in step 1. to build-tools folder (I didn't want to mess with PATH variable).

Code: Select all

apksigner.bat sign --ks NAME.keystore --ks- key-alias NAME YOURAPP.apk
6.) Your apk should now work on Android device without debugging; at least mine did.

HTH,

Bruno
"If you lie to the compiler, it will get its revenge."
Henry Spencer
http://www.pci-z.com/
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: [SB 2.20] APK corrupted *without* debugger enabled

Post by falsam »

Thanks bbanelli, but if it's only for testing on the device without downloading from Android Market, you don't need to sign the application.

Insert CloseDebugOutput() at the beginning of the code and create your application.

Tip to avoid zooming the screen.

Code: Select all

;No Zoom
!$('head').append('<meta name="viewport" content="width=device-width, maximum-scale=1.0, user-scalable=0">');

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
bbanelli
Posts: 107
Joined: Mon Jul 13, 2015 7:40 am

Re: [SB 2.20] APK corrupted *without* debugger enabled

Post by bbanelli »

Hi falsam,

thanks for the hint! :) How can I handle proper screen dimensions in that case? My gadgets/windows seem to be out of scale (too big) with this code, and I'd like to make them universally big for every device (thus using functions like DesktopWidth/WIndowWidth to handle properly).

With your code:
Image

Without your code:
Image

What would be best approach here? BTW, application (apk) looks like the version with your code.

Nevertheless, this should either be documented, or mitigated from SB's interface somehow, IMO.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
http://www.pci-z.com/
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: [SB 2.20] APK corrupted *without* debugger enabled

Post by tj1010 »

There is a conflict in the manifests of built apk that causes loader to throw an error when unsigned and no-debugger-checked.

You should be able to just use my sign tool on an apk SB builds without debug checked. http://forums.spiderbasic.com/viewtopic ... t=10#p3414

I can't test anything.. I haven't been able to get android loader to load apks built since 2.20 with or without debug checked.
Post Reply