Jump to content
Sign in to follow this  
pcplayer99

Delphi 10.4.2 CE support Android API 30

Recommended Posts

I have installed Delphi 10.4.2 CE version. All configurations is default by delphi installer.

My phone is OPPO and its Android version is Android 11.

 

New a FireMonkey project, connected my phone to my PC, and run it, everythiing is OK.

 

But if I upload this APP to Google play APP store,  it says APP's API level is 29, it must be API level 30.

 

I run "C:\Users\Public\Documents\Embarcadero\Studio\21.0\CatalogRepository\AndroidSDK-2525-21.0.40680.4203\SDK Manager.exe“, it is installed by Delphi. And there are Android 10 (API 29), Android 9(API 28) ... etc. There are no API 30.

 

So, I run "C:\Users\Public\Documents\Embarcadero\Studio\21.0\CatalogRepository\AndroidSDK-2525-21.0.40680.4203\tools\bin\sdkmanager.bat" to download API 30 and its done.

And then re-start "SDK Manager.exe", I can see "Android 11(API 30)" in it.

And in this directroy "C:\Users\Public\Documents\Embarcadero\Studio\21.0\CatalogRepository\AndroidSDK-2525-21.0.40680.4203\platforms", there was added a directory named "android-30". So it seems I have API 30 in my system.

 

In Delphi IDE menu: Tools - Options - Deployment - SDK Manager, SDK API-level location option is set by Delphi, it is "C:\Users\Public\Documents\Embarcadero\Studio\21.0\CatalogRepository\AndroidSDK-2525-21.0.40680.4203\platforms\android-29", I changed it to "C:\Users\Public\Documents\Embarcadero\Studio\21.0\CatalogRepository\AndroidSDK-2525-21.0.40680.4203\platforms\android-30";

 

And then re-deploy this APP and upload to Google play, it still says my APP is on API 29.

 

I can not find any tips in IDE menu to change API level, so I check "AndroidManifest.xml" under "D:\MyProjectFile\Android64\Release", there is:

<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29" /> 

 

I try to modify "D:\MyProjectFile\AndroidManifest.template.xml" from default:

<uses-sdk android:minSdkVersion="%minSdkVersion%" android:targetSdkVersion="%targetSdkVersion%" />

to:

<uses-sdk android:minSdkVersion="%minSdkVersion%" android:targetSdkVersion="30" />

to force it be API-30.

And re-build, deploy, and then upload to Google play, it works. No warning messages.

 

But, if I set project's "Configuration" to "Development" in IDE and press F9 to let it run in my phone, when it is installing in my phone, it is failed, and Delphi shows error message: adb: failed to install D:\MyProjectFile\Android64\Debug\testAndroid_11\bin\testAndroid_11.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

 

And then I change "AndroidManifest.template.xml" to default, and re-build and deploy and press F9, it has installed in my phone success and worked fine. And then I check "AndroidManifest.xml", it is "<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29" /> " again.

 

Repeat modify "AndroidManifest.template.xml" again and again, I'm sure if I set targetSDKVersion=29, it can install in my phone successed, if I changed it to targetSDKVersion=30, it install in my phone will be failed and the error message is: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES].

 

If I change targetSDKVersion=29 to targetSDKVersion=30,  and then set my project Configuration to "Application Store"  build and deploy then I got my AAB file and can upload Google play successed, but I am not sure if it can installing success when a phone install it from Google play.

 

I have searched on internet, but no any message about this.

 

SDK_Manager.jpg

development.jpg

Share this post


Link to post
7 hours ago, pcplayer99 said:

Repeat modify "AndroidManifest.template.xml" again and again, I'm sure if I set targetSDKVersion=29, it can install in my phone successed, if I changed it to targetSDKVersion=30, it install in my phone will be failed and the error message is: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES].

It's because Delphi 10.4.2 is using Jarsigner instead of APKSigner, which is required for APKs with a target SDK of 30 or higher. There are ways around it, however you are just delaying the inevitable. The bottom line is: If you want to stay current with Android development (or iOS, especially if deploying to the app stores), stay current with Delphi.

 

 

Share this post


Link to post

Thanks Vave.

According to your tips, I googled on line and got this: 

xamarin.android - Xamarin App - Can't deploy to Android 11 emulator - Stack Overflow

 

Its says that:

"Apps that target Android 11 (API level 30) that are currently only signed using APK Signature Scheme v1 must now also be signed using APK Signature Scheme v2 or higher. Users can't install or update apps that are only signed with APK Signature Scheme v1 on devices that run Android 11."

Share this post


Link to post

For sign apk by Jarsigner ( APK Signature Scheme v2 ) you need: 

 

1. Edit CodeGear.Deployment.Targets  add section

  <Target Name="_AndroidApkSigner" Condition="('$(Platform)'=='$(cAndroid32ArmPlatform)' Or '$(Platform)'=='$(cAndroid64ArmPlatform)') And '$(KeyStoreFile)'!='' And '$(AndroidAppBundle)'=='false'">
    <Message Text="Start Apk Signer."/>
    <Exec Command="&quot;$(ApkSigner)&quot; sign --ks $(KeyStoreFile) --ks-pass pass:$(KeyStorePass) $(SIGNED_APK_FILENAME)" ContinueOnError="True">
        <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
        <Output TaskParameter="StdOutEncoding" PropertyName="StdOut"/>
    </Exec>
  </Target>

2. add line _AndroidApkSigner; in section <DeployDependsOnTargets>

  <PropertyGroup>
    <DeployDependsOnTargets>
      ...
      _CheckKeyStore;
      _AndroidSign;
      _AndroidZipAlign;
      _AndroidApkSigner; 
      _CheckAPKFileOutputResult;
      _CheckAABFileOutputResult;
      _DeleteAndroidAssetsInfoFile;
      ...
    </DeployDependsOnTargets>

3. Create New IDE Environment Variable ApkSigner with value (SDK path)\android-sdk-windows\build-tools\29.0.2\apksigner.bat

 

image.thumb.png.8d4fe2ea69ef6c6cd50b83ee87a2fed4.png

 

Thanks to Stas for this solution

 

diff for file CodeGear.Deployment.Targets

image.thumb.png.620fc47688ee3908818dfc896e440073.png

Edited by Dmitry Sh.
  • Like 2

Share this post


Link to post

Thanks Dmitry.

 

It works!

 

A little update:

<Exec Command=""$(ApkSigner)" sign --ks $(KeyStoreFile) --ks-pass pass:$(KeyStorePass) $(SIGNED_APK_FILENAME)" ContinueOnError="True">

when open project, it shows a error message, and then fail.

 

I look through carefully the CodeGear.development.Targets file, found that:

<Exec Command="&quot;$(BDS)\bin\convert.exe&quot; -b -e.fsx &quot;%(ConvertForm.BaseName)&quot;" ContinueOnError="True">

<Exec Command="&quot;$(BDS)\bin\convert.exe&quot; -b -e.fsx &quot;%(ConvertForm.BaseName)&quot;" ContinueOnError="True">

 

So, I update the above line to:

<Exec Command="&quot;$(ApkSigner)&quot; sign --ks $(KeyStoreFile) --ks-pass pass:$(KeyStorePass) $(SIGNED_APK_FILENAME)" ContinueOnError="True">

And open project successed.

 

And then I can install APK to my phone after I update android:targetSdkVersion="30" 

 

Thanks a lot.

Share this post


Link to post

Hi Dmitry,

My new progress:

 

Yesterday I have tested Android API-level 30 at a new blank FMX project, it's OK.

And then I have tested a old project at release mode, it still report the same error message: INSTALL_PARSE_FAILED_NO_CERTIFICATES

But if I selected debug mode, the same old project can install successed at API-level 30.

 

I  compared all XML files of release mode and debug mode but can not find anything. But if I change API-level 30 to 29 at release mode, it can installed successed.

 

Finally, I created a new project and added all files of the old project into it, and then at Android release mode, changed API-level to 30, builded and deployed to my phone, it was successed.

 

thanks Dmitry.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×