简体   繁体   中英

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

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?

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.

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.

The app needs a certificate to be able to publish to Google Play. This certificate identifies the app and author, so you are able to update the app.

Important: Don't lose the key you used to publish your app, otherwise you can't update it anymore.

You can sign your app both for release and debug mode, the Android SDK allows to sign it for debug, but you need your own key to sign for release. The release mode is the one that goes to Google Play.

There's good documentation about the publishing process for Android apps. You can have a look to more detailed information here: http://developer.android.com/tools/publishing/preparing.html and here: http://developer.android.com/tools/publishing/app-signing.html

Related to the difference between Release/Debug, I'm not sure, but my guess is that it'll be only related to Qt libraries, not to the Android native code generated in your build process, you can have a look at the size of the compiled versions for a better picture.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM