Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Android: Why is a QtApp-debug.apk created for a Release build?

Tags:

c++

android

apk

qt

I'm building my Qt/C++ Android application in Release build, however the following APK files are produced:

Release/android-build/bin/QtApp-debug.apk
Release/android-build/bin/QtApp-debug-unaligned.apk

I found this question which implies that the APK files are built in debug mode even for Release builds. The answers there imply that Release builds are possible only if you have a Certificate.

I followed the instructions there, and indeed after creating a Certificate, I get these files instead:

Release/android-build/bin/QtApp-release.apk
Release/android-build/bin/QtApp-release-unsigned.apk

Why do I need a Certificate to create a Release APK, and if there is no Certificate, is there a difference between Release build and Debug build, or do they both contain unoptimized code?

Edit: In light of the posted answer, I'd like to clarify that I'm asking why does not having a certificate necessitate for Qt Creator to compile C++ code with optimizations switched off and debug info added?

like image 441
sashoalm Avatar asked Apr 12 '14 08:04

sashoalm


People also ask

What is the difference between debug APK and release APK?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.

How do I create an APK in Qt?

Open your project with Qt Creator 4.11 or later choosing a Release Build . Select Projects > Build > Build Android APK > Create Templates to create the Android package template files such as AndroidManifest. xml which is the main file of concern here.


2 Answers

This seems to be a bug on the build process of Qt Creator. The C++ files are compiled as they should, according to the selected build configuration (with optimizations and no debug info on release mode). So no matter your APK is named QtApp-debug.apk, the binaries inside are compiled as you choose.

The problem comes when calling androiddeployqt. If you look at the source, it creates a release package if it receives --release or also when it receives --sign. Qt Creator never passes the --release, so it compiles files as it should, but androiddeployqt only generates a release APK when you use a certificate, because Qt Creator passes the --sign

What are the differences of androiddeployqt creating a debug package:

  • The package name
  • It includes a gdbserver binary (aprox 250 KB on arm-v7)
  • It call ant with 'debug' instead of 'release'. This is what makes your apk signed with a debug key

Not having a certificate is not turning off optimizations and adding debug info, it's just creating a debug package, with debug signature which is necessary if you don't add your own. So after all, maybe it's not a bug.

like image 71
Smasho Avatar answered Oct 11 '22 20:10

Smasho


It may be an old question, but I have witnessed the same problem with Qt 5.12.3, a Release build produced debug APK in Release directory.

This happened because I didn't check on 'Signed' checkbox (and if you check it, you will be asked for password) when starting QtCreator. After providing password I got the usual android-build-release-signed.apk file.

like image 27
Nulik Avatar answered Oct 11 '22 22:10

Nulik