apache / cordova-android

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

Support API level 29 (Android 10) #830

Closed almothafar closed 4 years ago

almothafar commented 4 years ago

Feature Request

Motivation Behind Feature

Because android 10 is announced and released, platforms should be updated to version 29 when I do cordova build android

https://developer.android.com/studio/releases/platforms

Currently, the API version supported with android-cordova 8.1.0 is 19-28 for android 4.4-9.0.0

https://cordova.apache.org/docs/en/latest/guide/platforms/android/

Alternatives or Workarounds

Using android studio directly to release and update platforms to build my aab, but I'm using docker to build the aab for automated operations.

breautek commented 4 years ago

I agree that cordova-android should be updated to target API Level 29 by default, but in the meantime you can use a preference android-targetSdkVersion to set the target API level. E.g:


<widget ...>
    <platform name="android">
        <preference name="android-targetSdkVersion" value="29" />
    </platform>
</widget>
almothafar commented 4 years ago

@breautek I tried that, still getting:

Command finished with error code 1: /app/platforms/android/gradlew :app:bundleRelease,-b,/app/platforms/android/build.gradle
/app/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following SDK components:
      platforms;android-28 Android SDK Platform 28
  Install the missing components using the SDK manager in Android Studio.
breautek commented 4 years ago

@almothafar Interesting... later tonight I'll try to experiment further.

breautek commented 4 years ago

@breautek I tried that, still getting:

Command finished with error code 1: /app/platforms/android/gradlew :app:bundleRelease,-b,/app/platforms/android/build.gradle
/app/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following SDK components:
      platforms;android-28 Android SDK Platform 28
  Install the missing components using the SDK manager in Android Studio.

I am unable to reproduce this behaviour with a very simple node app. Cordova finds my build tools sdk 29.0.0 just fine & it obeys the android-targetSdkVersion just fine for me. I added additonal print lines in my project gradle file to see which build tools sdk and target SDK it is using which I've pasted below.

> Configure project :app
BUILD TOOLS VERSION
29.0.0
TARGET SDK VERSION
DefaultApiVersion{mApiLevel=29, mCodename='null'}
...

I would suggest making sure everything is up to date, including the cordova CLI.

npm install cordova@9 -g

Also do ensure that your ANDROID_HOME system environment variable is set properly.

almothafar commented 4 years ago

Here is my dockefile: https://github.com/capellasolutions/ionic-cordova-docker You can change ANDROID_PLATFORMS_VERSION to 29 and try that, and you can see I got cordova already set to version 9.

breautek commented 4 years ago

@almothafar Can you just provide me a non-docker repo that reproduces the issue?

I can't get docker installed on my system as the installer errors with Segmentation fault when I try to add the docker repository on my system. The error only happens for me with this docker apt repo and I've spent enough time googling the issue with no clear answers on why it might be happening.

almothafar commented 4 years ago

I can confirm even outside the docker still have the same issue but without failing, what I did I opened SDK Manager, I removed platform 28, and set <preference name="android-targetSdkVersion" value="29" />, the build continues, added platform 28 back and used it:


Checking the license for package Android SDK Platform 28 in /Users/almothafar/Library/Android/sdk/licenses
License for package Android SDK Platform 28 accepted.
Preparing "Install Android SDK Platform 28 (revision: 6)".
"Install Android SDK Platform 28 (revision: 6)" ready.
Installing Android SDK Platform 28 in /Users/almothafar/Library/Android/sdk/platforms/android-28
"Install Android SDK Platform 28 (revision: 6)" complete.
"Install Android SDK Platform 28 (revision: 6)" finished.

Inside docker I get different users, so it can't be installed, it should be installed from the previous build process.

Well, it is hard to provide a project now, but I can give you some steps:

  1. Start with a new Ionic angular app: https://ionicframework.com/docs/angular/your-first-app
  2. Set the config.xml as what you like.
  3. Try to run the following command to build a new app:
ionic cordova build android --no-interactive --confirm --prod --aot --minifyjs --minifycss --optimizejs --release --buildConfig=build.json --verbose

Note that when you start to build an android app, the 3rd step, you may see some issues, a chain of issues until you reach a point it starts to build, luckly solvable issues, but annoying, because of these issues I prefer using docker, or Android Studio, not command line.

Issues like missing gradle from path, EACCES, Minimum supported Gradle version is X.x.x. Current version is Y.x.x


If you prefer to use docker again if that issue you had before is solved, download the docker file that I linked before inside your project, build a new image using:

docker build . -f Dockerfile -t ionic-builder

Create a new Dockerfile inside your project, let's call it mobile.Dockerfile, then paste the following line inside it:

FROM ionic-builder

ADD --chown=ionic  . .

RUN rm -rf ./www ./platforms ./plugins && \
    ionic cordova build android --no-interactive --confirm --prod --aot --minifyjs --minifycss --optimizejs --release --buildConfig=build.json -- -d &&\
    mkdir -p ./output/android && \
    mv ./platforms/android ./output/android

RUN rm -rf ./www ./platforms ./plugins && \
    ionic cordova prepare ios --no-interactive --confirm --prod --aot --minifyjs --minifycss --optimizejs --buildConfig=build.json -- -d &&\
    mkdir -p ./output/ios && \
    mv ./platforms/ios ./output/ios

then run the following commands:

docker build . -f mobile.Dockerfile -t ionic-release

docker run -v ./build-output:/app/mount --rm --entrypoint cp ionic-release:latest -r output/android/android mount

docker run -v ./build-output:/app/mount --rm --entrypoint cp ionic-release:latest -r output/ios/ios mount

The last 2 lines will extract built folders outside the docker image ionic-release to your project, but the issue will happen and fail when you build ionic-release, while ionic-builder needed one time if you don't do any change to Dockerfile, you may need to remove ios part anyway, it is not our issue here.

breautek commented 4 years ago

@almothafar I've updated my original comment regarding the use of the preference. I was not aware that platform-specific preferences needed to be a child of their respective platform tag.

almothafar commented 4 years ago

Edit: To keep this issue clean I moved my comment to #846

almothafar commented 4 years ago

What the estimated time for this to get released?

breautek commented 4 years ago

What the estimated time for this to get released?

TBD. There's still quite a few open tickets and PRs to merge in for the 9.x milestone.

sebj54 commented 4 years ago

Hi @breautek, any update about 9.0.0 version release?

breautek commented 4 years ago

Hi @breautek, any update about 9.0.0 version release?

https://github.com/apache/cordova-android/milestone/2

Needs to be merged in first before the release vote process even begins.

sebj54 commented 4 years ago

Ok, thanks for your quick answer!

As development seems paused, this may take weeks or months?

breautek commented 4 years ago

Ok, thanks for your quick answer!

As development seems paused, this may take weeks or months?

Potentially, likely months. Don't forget that Cordova is entirely volunteer based. Some PRs are waiting on requested changes or merge resolves from the original PR authors, who haven't been responsive (which means, someone may have to take over the PR). Sometimes, internal dependencies needs to be released before the public-facing libraries can be released, which has to go through the same kind of vote process.

It is definitely a slow moving engine. With that being said, @nightly is available, or you can also install from git. So you don't need to wait for an official release if something is really blocking your project. You can use a specific commit hash to ensure that things don't change without your knowledge. e.g:

cordova platform add https://github.com/apache/cordova-android.git#c56cd4d5a8fdf2fc80ee8a9f1c960f21fca87a9a

https://github.com/apache/cordova-android/commit/c56cd4d5a8fdf2fc80ee8a9f1c960f21fca87a9a is the current master's head commit.

sebj54 commented 4 years ago

Thanks for all these details!

I am conscious that this is a huge amount of work that is being done on developers' spare time. I totally understand why it can be long. Just to be clear: I wasn't complaining at all, I just wanted to know if there was a release date planned in order to plan updates for an app I developed.

I will try to use the master branch if I really need it, thanks for the suggestion!

wspresto commented 3 years ago

Helping out the next poor soul who found their way here. This helped me override the gradle property which actually picks the API level when building. Setting the environment variable seemed the least intrusive way. export ORG_GRADLE_PROJECT_cdvCompileSdkVersion=30

JesusRocks777 commented 3 years ago

Hi @wspresto

Thank you for this succinct workaround. My head was reeling by the time I got to your post!

Just so I'm 100% clear:

(1) is this the ONLY thing I need to do to be API level 29- or 30-ready?

(2) do I do this from the command line:

(a) during the debug build process, (b) or during the release build process?

I'm using Cordova 10.0.0.

Thanks very much.

wspresto commented 3 years ago

I am using this workaround to build targeting API 30.

1.) AFAIK, yes. 2.) Consider this is an experimental flag, I would recommend only dev/debug.

FWIW, I am happy with the workaround. Sad to see cordova team is not keeping up with the times by updating their code faster. Seems to be working so long as you have the appropriate API level SDK tools installed on your machine.

JesusRocks777 commented 3 years ago

Thank you very much @wspresto. I have API level 29 SDK tools installed, so I'll stick to that level.

Can I ask one final thing?

Do I do this after the "cordova requirements" command, or after the "cordova build android" command?

Thank you!