Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom Gradle properties to read minSdkVersion value from config.xml #655

Merged
merged 9 commits into from
Feb 13, 2019

Conversation

brodybits
Copy link
Contributor

@brodybits brodybits commented Feb 8, 2019

Based on proposal by @erisu in #508 (comment), along with a few more changes:

  • some minor fixes to GradlePropertiesParser configuration
  • quick fix to handle minSdkVersion correctly
  • updates from review
  • now limited to minSdkVersion setting

I think some more improvements are needed to make the behavior easier to understand and maintain, hope I will get a chance to revisit after the new release is available.

FUTURE TODO:

  • some cleanup & improvements by @dpogue in a branch referenced below are not included here

Resolves ref: #508

erisu and others added 3 commits February 8, 2019 11:36
Accepts users defined minSdkVersion and targetSdkVersion from config.xml.
Co-authored-by: エリス <ellis.bryan@gmail.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
erisu
erisu previously requested changes Feb 9, 2019
Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also be recommend to add our defaults to this._defaults in the constructor method.

Same as how @dpogue did it with his commit in his repo: dpogue@d18f8d1

bin/templates/cordova/lib/prepare.js Outdated Show resolved Hide resolved
bin/templates/cordova/lib/prepare.js Outdated Show resolved Hide resolved
@brodybits brodybits changed the title Use custom Gradle properties to read SDK versions from config.xml [WIP] Use custom Gradle properties to read SDK versions from config.xml Feb 10, 2019
@brodybits
Copy link
Contributor Author

Marked as WIP for now. I would like to resolve #657 before continuing with rework on this one.

@brodybits
Copy link
Contributor Author

I had some trouble using cdvCompileSdkVersion to configure the target SDK version, which is related to issue #657. My idea is to go ahead with the proposed changes for cordova-android 8 and then revisit and refine at some point in the future. If anyone has a better idea please come forward.

I would like to get PRs #656, #663, and #664 merged first, and test these changes with master before we merge this one.

@brodybits brodybits changed the title [WIP] Use custom Gradle properties to read SDK versions from config.xml [WIP] Use custom Gradle properties to read minSdkVersion from config.xml Feb 12, 2019
@brodybits
Copy link
Contributor Author

brodybits commented Feb 12, 2019

I resolved the review comments above, now limited the changes to handle minSdkVersion. I encountered more problems dealing with compile or target SDK value, would like to keep outside the scope of this PR.

P.S. I still did not get a chance to test my recent work, keeping it as a WIP PR for now.

@codecov-io
Copy link

codecov-io commented Feb 12, 2019

Codecov Report

Merging #655 into master will decrease coverage by 0.21%.
The diff coverage is 38.46%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #655      +/-   ##
=========================================
- Coverage   64.61%   64.4%   -0.22%     
=========================================
  Files          18      18              
  Lines        1820    1826       +6     
=========================================
  Hits         1176    1176              
- Misses        644     650       +6
Impacted Files Coverage Δ
bin/templates/cordova/lib/prepare.js 36.3% <0%> (-0.38%) ⬇️
...lates/cordova/lib/config/GradlePropertiesParser.js 74.07% <55.55%> (-9.26%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 719acd3...393b440. Read the comment docs.

@erisu
Copy link
Member

erisu commented Feb 12, 2019

I am dismissing the review block as the changes were applied. I will review it again when it is no longer a WIP PR.

As for the targetSdkVersion, I not sure what issues you saw. With my original changes, it worked but I didn't use the cdv prefix and is maybe why I didn't see what you saw.

@erisu erisu dismissed their stale review February 12, 2019 22:43

Correction were applied.

@brodybits
Copy link
Contributor Author

I will review it again when it is no longer a WIP PR.

Thanks. I cannot promise when I will be able to continue with testing and fixing this one right now. I wouldn't mind if you or anyone else wants to take it over.

As for the targetSdkVersion, I not sure what issues you saw.

#657 was the main one. I tried quite a few things, nothing worked right for me. The compileSdkVersion and targetSdkVersion do not always seem to be the same thing, more details in #657.

I also had some trouble using privateHelpers.getProjectTarget to get the targetSdkVersion value.

I gave some reasons in #508 (comment) why I would favor limiting these changes to minSdkVersion.

You are welcome to try it yourself, I don't have much time to test or discuss any further right now.

@brodybits brodybits changed the title [WIP] Use custom Gradle properties to read minSdkVersion from config.xml Use custom Gradle properties to read minSdkVersion from config.xml Feb 13, 2019
@brodybits brodybits changed the title Use custom Gradle properties to read minSdkVersion from config.xml Use custom Gradle properties to read minSdkVersion value from config.xml Feb 13, 2019
@brodybits brodybits requested a review from erisu February 13, 2019 00:34
@brodybits
Copy link
Contributor Author

brodybits commented Feb 13, 2019

Now tested, requesting final review from @erisu.

P.S. I would like to merge this proposal upon approval. In case anyone else decides to merge this proposal it should be a squash merge with the Co-authored-by comments preserved in the commit message.

Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I ran the following test

$ npx cordova@nightly create androidTest3 com.foobar.androidTest3 androidTest3 && cd $_
$ npx cordova@nightly platform add github:brodybits/cordova-android\#custom-gradle-properties
Adding android project...
Creating Cordova project for the Android platform:
	Path: platforms/android
	Package: com.erisu.androidTest3
	Name: androidTest3
	Activity: MainActivity
	Android target: android-28
Subproject Path: CordovaLib
Subproject Path: app
Android project created with cordova-android@8.0.0-dev
...

$ npx cordova@nightly build android
...
BUILD SUCCESSFUL in 10s
...
$ aapt dump badging app-debug.apk
package: name='com.foobar.androidTest3' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
targetSdkVersion:'28'
...

$ npx cordova@nightly run android
BUILD SUCCESSFUL in 0s
...
INSTALL SUCCESS
LAUNCH SUCCESS
...

$ vi config.xml
... added <preference name="android-targetSdkVersion" value="26" />

$ npx cordova@nightly build android
...
BUILD SUCCESSFUL in 2s
...
$ aapt dump badging app-debug.apk
package: name='com.foobar.androidTest3' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
targetSdkVersion:'26'

@brodybits brodybits merged commit 867da56 into apache:master Feb 13, 2019
@brodybits brodybits deleted the custom-gradle-properties branch February 13, 2019 01:11
@brodybits
Copy link
Contributor Author

Thanks @erisu for the extra testing.

So the android-minSdkVersion preference is now properly handled by the Gradle scripts, while the android-targetSdkVersion preference works because the value is copied to AndroidManifest.xml and not overridden by the Gradle scripts. (I think the second one should eventually go away, once we can reapply #664 (remove uses-sdk from AndroidManifest.xml), for another major release in the future.)

I did also try with the following command, which seemed to work properly:

cordova build android -- --gradleArg=-PcdvMinSdkVersion=21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants