apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

Support new Android App Bundle package format #729

Closed fortunella closed 4 years ago

fortunella commented 5 years ago

Feature Request

Motivation Behind Feature

Google recommends using the new Android App Bundle format for apps uploaded to Google Play. When you upload an APK a warning is displayed which encourages to use the newer format.

Feature Description

Google provides information on the new package format on: https://developer.android.com/platform/technology/app-bundle It would be great if Cordova would support this new package format out of the box or with a parameter for the build command.

janpio commented 5 years ago

For reference: Previous question issue about support of bundles: https://github.com/apache/cordova-android/issues/610

niren777 commented 4 years ago

I'm able to generate both 32-bit and 64-bit versions using cordova build android --release and cordova build android --release --xwalk64bit respectively

As Android App Bundle package is not supported by cordova-android yet, should I upload both android-armv7-debug.apk and android-arm64-release.apk to play store to support both 32-bit and 64-bit mobiles?

By uploading both the apk files, I'll end up creating one more project for the 64-bit version and also with different version code as mentioned by android here https://developer.android.com/google/play/publishing/multiple-apks

breautek commented 4 years ago

I'm able to generate both 32-bit and 64-bit versions using cordova build android --release and cordova build android --release --xwalk64bit respectively

As Android App Bundle package is not supported by cordova-android yet, should I upload both android-armv7-debug.apk and android-arm64-release.apk to play store to support both 32-bit and 64-bit mobiles?

Because crosswalk uses native libraries, yes you will have to build a 32bit and a 64bit version of the APK and upload them both to the google play store. This is what I do for my apps currently since I haven't moved away from crosswalk yet.

niren777 commented 4 years ago

@breautek Thanks for the comment. Should I need to create another project in Google play for 64-bit version of apk? or Is one project enough to support both 32-bit and 64-bit versions? Also should I need to generate both the apk files with different android version code?

breautek commented 4 years ago

Both APKs needs to have the same package ID. So they get uploaded to the same project. When you enable multiple APKs, the build will add a digit to your versionCode to represent 32bit/64bit. Google play store will automatically select the proper APK for the device that is installing the app.

To prevent hijacking this thread, if you have anymore questions about multiple APKs you should open up a new issue.

malvarez-troop commented 4 years ago

Hi, We have generated the bundle with Android Studio.

The steps are:

1) Launch Android Studio 2) Go To Import Project (Eclipse ADT, Gradle, etc). 3) Select Android platform directory in your project (/platforms/android). 4) Wait for finish the Sync 5) Go to Build > Generate Sign Bundle 6) Complete Signing info 7) Upload de .aab file generated (in path /platforms/android/outputs/

Note: if you have problem whith minSDK version, fix this and make a resync

JonSmart commented 4 years ago

Whilst the Android Studio work around is great, I would like to integrate this with our CI Server and therefore interested to understand when the Cordova CLI can build with this output instead of APK.

janpio commented 4 years ago

We are always open for PRs from the community!

You will have to understand how the current Android build works, then see if there is an equivalent for the commands for App Bundles (vs. APKs) and then adapt these back into Cordova Android.

(https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/build, https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/Api.js#L253-L314 and https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/build.js will probably be your starting point, on to https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/builders/ProjectBuilder.js which seems to do the actual building - if you have any questions or need help, feel free to ping me here or on slack.cordova.io)

PavlosIsaris commented 4 years ago

Hi, We have generated the bundle with Android Studio.

The steps are:

  1. Launch Android Studio
  2. Go To Import Project (Eclipse ADT, Gradle, etc).
  3. Select Android platform directory in your project (/platforms/android).
  4. Wait for finish the Sync
  5. Go to Build > Generate Sign Bundle
  6. Complete Signing info
  7. Upload de .aab file generated (in path /platforms/android/outputs/

Note: if you have problem whith minSDK version, fix this and make a resync

What android-cordova version did you use to do that? Didn't you have a problem with the android-gradle plugin version?

fabiodiniz commented 4 years ago

Now I can't upload a new app to Play Store. The warning is not allowing me to send it to production. It suggests to generate an Android App Bundle.

image

image

anh1979 commented 4 years ago

We are facing the same problem right now. Just as @JonSmart wrote above, a solution to integrate this with CI Servers is required in our scenario, as we are working with a great number of apps in an automated process.

Please prioritize, if at all possible.

janpio commented 4 years ago

@anh1979 As I wrote before we are happy to review any Pull Requests done by the community.

GuilhermeLessa commented 4 years ago

Now I can't upload a new app to Play Store. The warning is not allowing me to send it to production. It suggests to generate an Android App Bundle.

image

image

These warnings do not block the submission of the app. They are only warnings of recommendations. Check other pending items in the left side menu. Play Console is not very intuitive.

@fabiodiniz na verdade esses avisos são somente avisos, eles não estão impedindo você de lançar para produção. Você consegue enviar para produção subindo os .apk's como sempre. Veja os itens do menu esquerdo, todos devem estar "checkados" (verdes). O que acontece é que você deve ter itens pendentes de revisão nesse menu.

fabiodiniz commented 4 years ago

@fabiodiniz na verdade esses avisos são somente avisos, eles não estão impedindo você de lançar para produção. Você consegue enviar para produção subindo os .apk's como sempre. Veja os itens do menu esquerdo, todos devem estar "checkados" (verdes). O que acontece é que você deve ter itens pendentes de revisão nesse menu.

@GuilhermeLessa vc tem razão amigo, confusão minha aqui, valeu 🙏

These warnings do not block the submission of the app. They are only warnings of recommendations. Check other pending items in the left side menu. Play Console is not very intuitive.

Yeah, u're right. My mistake 😳

jfoclpf commented 4 years ago

Hi, We have generated the bundle with Android Studio.

The steps are:

  1. Launch Android Studio
  2. Go To Import Project (Eclipse ADT, Gradle, etc).
  3. Select Android platform directory in your project (/platforms/android).
  4. Wait for finish the Sync
  5. Go to Build > Generate Sign Bundle
  6. Complete Signing info
  7. Upload de .aab file generated (in path /platforms/android/outputs/

Note: if you have problem whith minSDK version, fix this and make a resync

Any way of doing it only with command line using adb? I would add it to my building script saving a lot of time

viktor-shmigol commented 4 years ago

@jfoclpf I got it working on circle ci.

The steps are:

1 - run:
      name: Build android!
      command: 'ionic cordova build android --prod --release'

2  - run:
      name: Build an app bundle
      command: 'cd /Users/test_user/project/platforms/android && ./gradlew bundle'
3 - run:
      name: Signing an app bundle
      command: jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /Users/test_user/project/sign/my_key.keystore /Users/test_user/project/platforms/android/app/build/outputs/bundle/release/app.aab todoapp -storepass my_password

4 - Upload app.aab to google play.

lucasbasquerotto commented 4 years ago

Thanks, @viktor-shmigol, I was able to generate an aab file that way. The only thing, though, is that the reduction in size is almost negligible in my case (from 12.8MB to 11.8MB).

breautek commented 4 years ago

The aab file size is not the served file size. Google Play store will tell you what will be the approximate served file sizes for each device configuration when you upload the aab file.

dpogue commented 4 years ago

Speaking realistically, you’re not going to see much (any?) size savings for Cordova apps because the majority of the size is the web content assets and Google can’t strip any of that out.

krunal9421 commented 4 years ago

@breautek I have query regarding 30th May comment that we will have two different upload provision by Google for 64 and 32 bit apps? And do we need to two different apps with same or different android android-versionCode for release? because Ionic does not have any cli to build 64bit apk. Can you help me with this?

janpio commented 4 years ago

@krunal9421 Please open a new issue or better Stack Overflow question about this and don't derail this issue. Thanks.

jsaraiva commented 4 years ago

@jfoclpf I got it working on circle ci.

The steps are:

1 - run:
      name: Build android!
      command: 'ionic cordova build android --prod --release'

2  - run:
      name: Build an app bundle
      command: 'cd /Users/test_user/project/platforms/android && ./gradlew bundle'
3 - run:
      name: Signing an app bundle
      command: jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /Users/test_user/project/sign/my_key.keystore /Users/test_user/project/platforms/android/app/build/outputs/bundle/release/app.aab todoapp -storepass my_password

4 - Upload app.aab to google play.

Hello.

The instructions above are right on the money. Furthermore, and in case this helps anyone: You can skip the signing step itself. If you add a build.json file to your project with the release signing info (see https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#using-buildjson), then this will automatically generate a release-signing.properties file, which in turn will be used by the Gradle tasks (including the task to build the bundle). So, step 3 can be sidestepped entirely. Also, running the gradlew "bundle" task generates bundles for both debug and release. If you want to only generate the release version, use "bundleRelease" (or "bundleDebug" to get the debug version).

Cheers!

khoabuidev commented 4 years ago

@jfoclpf I got it working on circle ci.

The steps are:

1 - run:
      name: Build android!
      command: 'ionic cordova build android --prod --release'

2  - run:
      name: Build an app bundle
      command: 'cd /Users/test_user/project/platforms/android && ./gradlew bundle'
3 - run:
      name: Signing an app bundle
      command: jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /Users/test_user/project/sign/my_key.keystore /Users/test_user/project/platforms/android/app/build/outputs/bundle/release/app.aab todoapp -storepass my_password

4 - Upload app.aab to google play.

Thanks so much, working perfectly.

dpa99c commented 4 years ago

Speaking realistically, you’re not going to see much (any?) size savings for Cordova apps because the majority of the size is the web content assets and Google can’t strip any of that out.

@dpogue That's true for a very simple Cordova app, but if you start including plugins with native SDKs that contain architecture-specific compiled C libraries, then the app bundle starts to pay off since it only distributes the library variants specific to the device architecture rather than the library variant for every architecture (as a multi-arch APK does).

geeksilva97 commented 4 years ago

@jfoclpf I got it working on circle ci.

The steps are:

1 - run:
      name: Build android!
      command: 'ionic cordova build android --prod --release'

2  - run:
      name: Build an app bundle
      command: 'cd /Users/test_user/project/platforms/android && ./gradlew bundle'
3 - run:
      name: Signing an app bundle
      command: jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /Users/test_user/project/sign/my_key.keystore /Users/test_user/project/platforms/android/app/build/outputs/bundle/release/app.aab todoapp -storepass my_password

4 - Upload app.aab to google play.

This sounds awesome! But didn't work for me. When I run the ./gradlew bundle I'm getting the following output:

`

Configure project :CordovaLib publishNonDefault is deprecated and has no effect anymore. All variants are now published.

Configure project :app The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead. at build_1je5gdx9ebu802xao0249llns.run(/home/edy/workspaces/tutoriais/ionic/shareApp/platforms/android/app/build.gradle:143) Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.

FAILURE: Build failed with an exception.

BUILD FAILED in 7s `

geeksilva97 commented 4 years ago

I tried to run ./gradlew bundleRelese and ./gradlew bundleDebug but without success. My output sounds like OK but the .aab file is not generated.

The output is:

`> Configure project :CordovaLib publishNonDefault is deprecated and has no effect anymore. All variants are now published.

Configure project :app The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead. at build_1je5gdx9ebu802xao0249llns.run(/home/edy/workspaces/tutoriais/ionic/shareApp/platforms/android/app/build.gradle:143) Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead. BUILD SUCCESSFUL in 4s 23 actionable tasks: 23 up-to-date `

Are there any settings to be made? Forgot something important?

Thankful for any help!

@jfoclpf

breautek commented 4 years ago

@geeksilva97 in my PR I'm running gradlew :app:bundleDebug or gradlew :app:bundleRelease.

Try one of these, and let me know if this works for you or not. Thanks.

Also The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.

This is something that has been already addressed, so I believe you may be running an old version of cordova-android. You may need to update cordova-android to version 8.

jsaraiva commented 4 years ago

BTW, in case it helps anyone, here are my package.json scripts for buildings artifacts deployable in the Play Store:

"build-android-apk": "cordova build android --release",
"build-android-bundle": "cordova build android --release ; cd ./platforms/android/ ; ./gradlew bundleRelease",
"run-android": "cordova run android --release",

Using latest versions of cordova and cordova-android (8.0.0). The signing part (also done by bundleRelease) is handled by the build.json file, as I mentioned above. The resulting aab file is located at platforms/android/build/bundle .

Cheers!

geeksilva97 commented 4 years ago

@geeksilva97 in my PR I'm running gradlew :app:bundleDebug or gradlew :app:bundleRelease.

Try one of these, and let me know if this works for you or not. Thanks.

Also The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.

This is something that has been already addressed, so I believe you may be running an old version of cordova-android. You may need to update cordova-android to version 8.

You're right! My cordova-android was 7.x.x.I updated to cordova-android 8.0.0, but now I can't find the gradlew. :/

breautek commented 4 years ago

Running the normal build command once should install gradlew for you.

geeksilva97 commented 4 years ago

Awesome! With your help I got it. Thank you all.

To generate gradlew I executed the command

$ ./gradle wrapper --gradle-version=5.5.1 --distribution-type=bin

This generated to me a folder with gradlew.bat.

After I executed the command ./gradlew bundleDebug and it worked! My .aab file was generated.

geeksilva97 commented 4 years ago

Running the normal build command once should install gradlew for you.

Oh my God! I went the long way. Thank you!

breautek commented 4 years ago

Oh my God! I went the long way. Thank you!

Doesn't hurt to know what goes on behind the scenes ;)

tomriddle1234 commented 4 years ago

I can build aab with above info, but it still gets rejected from Google, saying no 64bit version code...

Clint258 commented 4 years ago

C:\Users\User\Desktop\UPKwiK\platforms>cd /Users/user/desktop/upkwik/platforms/android && ./gradlew bundle '.' is not recognized as an internal or external command, operable program or batch file.

please help me

Capture

breautek commented 4 years ago

C:\Users\User\Desktop\UPKwiK\platforms>cd /Users/user/desktop/upkwik/platforms/android && ./gradlew bundle '.' is not recognized as an internal or external command, operable program or batch file.

please help me

Capture

Window users have to use gradlew.bat instead of gradlew.

dpogue commented 4 years ago

Also, cordova-android@8.1.0 has been released, which includes bundle support. With 8.1.0 installed, you can use cordova build android --release -- --packageType=bundle to build bundles. (note the double set of -- -- hyphens)

cordova-android@8.1.0 has not been released, it has been tagged to begin the release voting process. It will be published to npm when it has been released.

breautek commented 4 years ago

Also, cordova-android@8.1.0 has been released, which includes bundle support. With 8.1.0 installed, you can use cordova build android --release -- --packageType=bundle to build bundles. (note the double set of -- -- hyphens)

cordova-android@8.1.0 has not been released, it has been tagged to begin the release voting process. It will be published to npm when it has been released.

My bad, I edited my comment to avoid confusion.

Clint258 commented 4 years ago

Thank you, but i could generate my app with android studio, it was hard but actualy it works. But thanks for helping me

No dia quinta-feira, 12 de setembro de 2019, Norman Breau < notifications@github.com> escreveu:

Also, cordova-android@8.1.0 has been released, which includes bundle support. With 8.1.0 installed, you can use cordova build android --release -- --packageType=bundle to build bundles. (note the double set of -- -- hyphens)

cordova-android@8.1.0 has not been released, it has been tagged to begin the release voting process. It will be published to npm when it has been released.

My bad, I edited my comment to avoid confusion.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-android/issues/729?email_source=notifications&email_token=AMN5L6PMPOQOY32C7YR5KPTQJJPUZA5CNFSM4HLQ5F7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6SKYIY#issuecomment-530885667, or mute the thread https://github.com/notifications/unsubscribe-auth/AMN5L6I66QY6QW34O5D2GLTQJJPUZANCNFSM4HLQ5F7A .

geeksilva97 commented 4 years ago

To help more people I made a short series of videos on YouTube. In these three videos I show you how you can build your app.

Check out

https://www.youtube.com/playlist?list=PLfeu5i2CGb0uJeI8NshaN1TLXy1eJg2No

I hope this can help.

Clint258 commented 4 years ago

Ho thanks.. Can you make a video talking about cordova firebase plugin, to show notifications on ionic 4 applications using android platform.. These error are killing me

A sábado, 14/09/2019, 08:57, Edigleysson Silva notifications@github.com escreveu:

To help more people I made a short series of videos on YouTube. In these three videos I show you how you can build your app.

Chekc out

https://www.youtube.com/playlist?list=PLfeu5i2CGb0uJeI8NshaN1TLXy1eJg2No

I hope this can help.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-android/issues/729?email_source=notifications&email_token=AMN5L6OIYEHSSBJGECAOBM3QJSDNRA5CNFSM4HLQ5F7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6WV7CI#issuecomment-531455881, or mute the thread https://github.com/notifications/unsubscribe-auth/AMN5L6KGAEQJG3JCACTXZ7LQJSDNRANCNFSM4HLQ5F7A .

Clint258 commented 4 years ago

Ho, não sabia que falavas português... Então estou a ter problemas com notificações em ionic 4 por causa do problema no plugin de firebase que deu em abril.. Podes me ajudar?

A domingo, 15/09/2019, 08:10, Clint Lucas clintlucasfernando@gmail.com escreveu:

Ho thanks.. Can you make a video talking about cordova firebase plugin, to show notifications on ionic 4 applications using android platform.. These error are killing me

A sábado, 14/09/2019, 08:57, Edigleysson Silva notifications@github.com escreveu:

To help more people I made a short series of videos on YouTube. In these three videos I show you how you can build your app.

Chekc out

https://www.youtube.com/playlist?list=PLfeu5i2CGb0uJeI8NshaN1TLXy1eJg2No

I hope this can help.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-android/issues/729?email_source=notifications&email_token=AMN5L6OIYEHSSBJGECAOBM3QJSDNRA5CNFSM4HLQ5F7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6WV7CI#issuecomment-531455881, or mute the thread https://github.com/notifications/unsubscribe-auth/AMN5L6KGAEQJG3JCACTXZ7LQJSDNRANCNFSM4HLQ5F7A .

geeksilva97 commented 4 years ago

Sim. Podemos chegar a solução. O que está havendo?

Clint258 commented 4 years ago

parece que o cordova firibase plugin teve um erro. podes acompanhar melhor nesse link https://github.com/arnesson/cordova-plugin-firebase/issues/1057

This is due to the firebase updates on April 05. Here https://firebase.google.com/support/release-notes/android#update_-_april_02_2019, I found the last working versions and adjusted my project.properties accordingly like so

mas nao funciona na mesma

Edigleysson Silva notifications@github.com escreveu no dia domingo, 15/09/2019 à(s) 13:29:

Sim. Podemos chegar a solução. O que está havendo?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-android/issues/729?email_source=notifications&email_token=AMN5L6KEG6V2PQH3O5SUY6LQJYMBPA5CNFSM4HLQ5F7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XO2TQ#issuecomment-531557710, or mute the thread https://github.com/notifications/unsubscribe-auth/AMN5L6OMYLOG7DOXVUDP7X3QJYMBPANCNFSM4HLQ5F7A .

timbru31 commented 4 years ago

Guys, these seems a) off topic and b) please stick to English
You might want to continue this chat on a more suitable platform than a closed GitHub issue :) Thanks!

Clint258 commented 4 years ago

ok tim

Tim Brust notifications@github.com escreveu no dia segunda, 16/09/2019 à(s) 01:11:

Guys, these seems a) off topic b) please stick to English You might want to continue this chat on a more suitable platform than a closed GitHub issue :) Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/cordova-android/issues/729?email_source=notifications&email_token=AMN5L6I64NVVLJ6TWZUWFETQJ26LHA5CNFSM4HLQ5F7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6X27GQ#issuecomment-531607450, or mute the thread https://github.com/notifications/unsubscribe-auth/AMN5L6LJ2I5PECUBFU2QC2TQJ26LHANCNFSM4HLQ5F7A .

rushdone commented 4 years ago

@fabiodiniz, i got same problem with you about that warning sign..may know what mistake did u noticed until u can publish without using android app bundle?

breautek commented 4 years ago

@fabiodiniz, i got same problem with you about that warning sign..may know what mistake did u noticed until u can publish without using android app bundle?

Google does not prevent you from publishing APKs. I still do this in my personal projects. Google however, does require you to supply an APK that contains the 64bit architecture of native libraries, if you're app includes native libraries.

You can either do this by including all architectures you support in a single APK or by using a multi-apk setup where each APK is for a specific architecture.

Google encourages you to include all shared library architectures in a form of a bundle. This would be best deployment strategy moving forward, but they don't stop you from using an any of the APK deployment strategies.

desmeit commented 4 years ago

I tried with 8.1.0:

cordova build android --release
cd platforms/android
./gradlew bundleRelease

But I get an error:

> Configure project :app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see:     http://d.android.com/r/tools/update-dependency-configurations.html
An exception occurred while trying to find the Android build tools.
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.

FAILURE: Build failed with an exception.

* Where:
Script '/XXX/platforms/android/CordovaLib/cordova.gradle' line: 121

* What went wrong:
A problem occurred evaluating project ':app'.
> Unable to determine Android SDK directory.

What could be the reason?

breautek commented 4 years ago

@desmeit cordova cannot find your android sdk directory, so you might have a misconfiguration somewhere.

Please open a new issue and fill out the form appropriately as it will tell us everything we will need to know to further help you. You may even find the problem yourself in the process.

Thanks.