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

Improve Gradle Build Arguments #699

Merged
merged 8 commits into from
Apr 6, 2019
Merged

Improve Gradle Build Arguments #699

merged 8 commits into from
Apr 6, 2019

Conversation

erisu
Copy link
Member

@erisu erisu commented Mar 27, 2019

Platforms affected

android

Motivation and Context

Description

  • Remove <uses-sdk> from AndroidManifest.xml (minSdkVersion, maxSdkVersion, and targetSdkVersion)
  • Remove AndroidManifest setter and getters for minSdkVersion, maxSdkVersion, and targetSdkVersion
  • Updated compileSdkVersion
  • Remove spec tests.
  • Improve ways of setting build SDK values:
    • minSdkVersion
    • maxSdkVersion
      • Added build flag (will set command-line argument and take priority)
      • Added config.xml <preference> name android-maxSdkVersion (Updates gradle.properties)
    • targetSdkVersion
      • Added build flag (will set command-line argument and take priority)
      • Added config.xml <preference> name android-targetSdkVersion (Updates gradle.properties)

Testing

  • npm t

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@erisu erisu requested a review from dpogue March 27, 2019 09:43
@brodybits brodybits mentioned this pull request Mar 27, 2019
5 tasks
Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

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

This looks pretty good to me, a few minor comments.
I think we should review what we do with compileSdkVersion and how that interacts with targetSdkVersion.

@@ -266,6 +270,8 @@ module.exports.help = function () {
console.log(' \'--prepenv\': don\'t build, but copy in build scripts where necessary');
console.log(' \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs.');
console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build. Useful for uploading multiple APKs.');
console.log(' \'--maxSdkVersion=#\': Override maxSdkVersion for this build. Useful for uploading multiple APKs.');
Copy link
Member

Choose a reason for hiding this comment

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

Remove "Useful for uploading multiple APKs." from minSdkVersion, maxSdkVersion, andtargetSdkVersion.

There's also probably no value in supporting maxSdkVersion since they really really strongly discourage using it (your app will not be compatible with newer versions of Android)

Copy link
Member Author

@erisu erisu Mar 29, 2019

Choose a reason for hiding this comment

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

At best, we might only be able to add to the printout (Not Recommended).

We already supported the setting of the maxSdkVersion property through config.xml and in which sets it in AndroidManifest.xml.

This PR moves the maxSdkVersion definition into the Gradle's workflow and removes from AndroidManifest.xml.

This does add a new command line option to exposes alternative ways for defining this value other than config.xml. I thought it was a missed option because we supported min and believe there was no harm to add.

If we want to remove maxSdkVersion altogether, it then becomes a major change. As for future planning, it would be best if I don't add the new command-line option then. We probably should just add warnings that the maxSdkVersion setting will be deprecated in the next major.

Thoughts and Opinions?

ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
//ext.cdvCompileSdkVersion = project.ext.defaultCompileSdkVersion
}
ext.cdvCompileSdkVersion = cdvCompileSdkVersion == null ? (
Copy link
Member

Choose a reason for hiding this comment

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

compileSdkVersion should probably default to targetSdkVersion, unless it is explicitly set

@erisu erisu marked this pull request as ready for review March 30, 2019 04:14
@codecov-io
Copy link

codecov-io commented Mar 30, 2019

Codecov Report

Merging #699 into master will decrease coverage by 0.4%.
The diff coverage is 46.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #699      +/-   ##
==========================================
- Coverage   64.38%   63.98%   -0.41%     
==========================================
  Files          18       18              
  Lines        1828     1824       -4     
==========================================
- Hits         1177     1167      -10     
- Misses        651      657       +6
Impacted Files Coverage Δ
bin/templates/cordova/lib/AndroidManifest.js 100% <ø> (ø) ⬆️
bin/lib/create.js 92.72% <ø> (ø) ⬆️
bin/templates/cordova/lib/prepare.js 35.81% <0%> (-0.5%) ⬇️
...lates/cordova/lib/config/GradlePropertiesParser.js 76.66% <100%> (+2.59%) ⬆️
bin/templates/cordova/lib/build.js 26.77% <40%> (+0.75%) ⬆️

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 9531dbb...9f67d1f. Read the comment docs.

@erisu
Copy link
Member Author

erisu commented Apr 1, 2019

Test Case

config.xml

minSdkVersion

<preference name="android-minSdkVersion" value="20" />

$ cordova create test1 com.foobar.test1 test1 && $_
$ cordova platform add github:erisu/cordova-android\#sync-fix
$ cordova build android

BUILD SUCCESSFUL in 2s
44 actionable tasks: 44 executed

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test1' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'20'
targetSdkVersion:'28'

<preference name="android-minSdkVersion" value="21" />

$ cordova build android

BUILD SUCCESSFUL in 1s
44 actionable tasks: 9 executed, 35 up-to-date

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test1' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'21'
targetSdkVersion:'28'

maxSdkVersion

<preference name="android-maxSdkVersion" value="20" />

$ cordova create test2 com.foobar.test2 test2 && $_
$ cordova platform add github:erisu/cordova-android\#sync-fix
$ cordova build android

BUILD SUCCESSFUL in 2s
44 actionable tasks: 44 executed

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test2' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
maxSdkVersion:'20'
targetSdkVersion:'28'

<preference name="android-maxSdkVersion" value="21" />

$ cordova build android

BUILD SUCCESSFUL in 1s
44 actionable tasks: 4 executed, 40 up-to-date

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test2' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
maxSdkVersion:'21'
targetSdkVersion:'28'

targetSdkVersion

<preference name="android-targetSdkVersion" value="20" />

$ cordova create test3 com.foobar.test3 test3 && $_
$ cordova platform add github:erisu/cordova-android\#sync-fix
$ cordova build android

BUILD SUCCESSFUL in 2s
44 actionable tasks: 44 executed

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test3' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
targetSdkVersion:'20'

<preference name="android-targetSdkVersion" value="21" />

$ cordova build android

BUILD SUCCESSFUL in 0s
44 actionable tasks: 4 executed, 40 up-to-date

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test3' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
targetSdkVersion:'21'

Command-Line Argument

--minSdkVersion

$ cordova create test4 com.foobar.test4 test4 && $_
$ cordova platform add github:erisu/cordova-android\#sync-fix
$ cordova build android -- --minSdkVersion=20

BUILD SUCCESSFUL in 2s
44 actionable tasks: 44 executed

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test4' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'20'
targetSdkVersion:'28'
$ cordova build android -- --minSdkVersion=21

BUILD SUCCESSFUL in 1s
44 actionable tasks: 9 executed, 35 up-to-date

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test4' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'21'
targetSdkVersion:'28'

--maxSdkVersion

$ cordova create test5 com.foobar.test5 test5 && $_
$ cordova platform add github:erisu/cordova-android\#sync-fix
$ cordova build android -- --maxSdkVersion=20

BUILD SUCCESSFUL in 2s
44 actionable tasks: 44 executed

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test5' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
maxSdkVersion:'20'
targetSdkVersion:'28'
$ cordova build android -- --maxSdkVersion=21

BUILD SUCCESSFUL in 0s
44 actionable tasks: 3 executed, 41 up-to-date

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test5' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
maxSdkVersion:'21'
targetSdkVersion:'28'

--targetSdkVersion

$ cordova create test6 com.foobar.test6 test6 && $_
$ cordova platform add github:erisu/cordova-android\#sync-fix
$ cordova build android -- --targetSdkVersion=20

BUILD SUCCESSFUL in 2s
44 actionable tasks: 44 executed

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test6' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
targetSdkVersion:'20'
$ cordova build android -- --targetSdkVersion=21

BUILD SUCCESSFUL in 0s
44 actionable tasks: 3 executed, 41 up-to-date

$ aapt dump badging platforms/android/app/build/outputs/apk/debug/app-debug.apk

package: name='com.foobar.test6' versionCode='10000' versionName='1.0.0' platformBuildVersionName='1.0.0' compileSdkVersion='28' compileSdkVersionCodename='9'
sdkVersion:'19'
targetSdkVersion:'21'

@erisu
Copy link
Member Author

erisu commented Apr 1, 2019

@dpogue This should now be ready for a final review.

For flexibility, `maxSdkVersion` is an available option to users but not recommended to set.
@erisu erisu requested a review from knight9999 April 4, 2019 23:40
@erisu erisu added this to the 8.0.1 milestone Apr 4, 2019
@erisu erisu moved this from In Progress to Pending Review in Apache Cordova: Next Release Planning and Tracking Apr 5, 2019
Copy link

@knight9999 knight9999 left a comment

Choose a reason for hiding this comment

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

No any problem.
All tests are green.

@drastik
Copy link

drastik commented Apr 6, 2019

Heck yes!

This solves an annoying few extra steps each compile. May be worth noting, Google play console just forced me to use min SDK 26 earlier today, rejecting .apk uploads with min target = 19.

This PR also closes:
#680
#675

@dpogue
Copy link
Member

dpogue commented Apr 6, 2019

@drastik I'm pretty sure Google's now requiring that the compileSdkVersion is set to a minimum of 26 for submission to the Play Store, but the minSdkVersion should be able to point to any previous version of Android.

@erisu erisu merged commit 485e6e0 into apache:master Apr 6, 2019
@erisu erisu deleted the sync-fix branch April 6, 2019 04:28
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.

Gradle Fails to sync after upgrading to Cordova Android 8.0
5 participants