-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat!: unify & fix gradle library/tooling overrides #1212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be rebased and there is also build failures.
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file '/cordova/sampleApp/platforms/android/app/build.gradle' line: 160
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'defaultSdkVersion' for project ':app' of type org.gradle.api.Project.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 3s
Command failed with exit code 1: /cordova/sampleApp/platforms/android/gradlew cdvBuildDebug -b /cordova/sampleApp/platforms/android/build.gradle
3a557b4
to
98b0684
Compare
Codecov Report
@@ Coverage Diff @@
## master #1212 +/- ##
==========================================
- Coverage 71.90% 71.08% -0.82%
==========================================
Files 21 22 +1
Lines 1694 1705 +11
==========================================
- Hits 1218 1212 -6
- Misses 476 493 +17
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything seems OK to my now.
I made one last commit, as testing the latest changes produced a fail build locally... The change ensure the settings have proper types. For example gradle expects a number for the target SDK setting and will crash if it receives a string, but it looks like Let me know what you think about the latest commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not really like us inventing our own template system, especially if it's only for one file. How about we remove TemplateFile
and use JS string templates instead like I did in cordova-js
?
So in this case, instead of reading the project.properties
and passing them through the TemplateFile class, we replace it with a file project-props-template.js
that looks like this:
module.exports = ({ SDK_VERSION }) => `
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-${SDK_VERSION}
apk-configurations=
renderscript.opt.level=O0
android.library=true
`.trimLeft();
create.js
can then just import that file and pass the desired SDK_VERSION
when calling the exported function.
@raphinesse I think I can do one better... I agree, having the |
Agreed, that's probably even better. |
Only thing about using |
Cool! I think that's a better solution. We should probably remove the placeholder and add a comment to the properties file now? |
Will do. I'll remove it completely to avoid confusion and add a generated file notice. Also just realised this isn't working... it's writing out an empty value for some reason... so I'm troubleshooting that right now. |
feeee5d
to
c1fbbd3
Compare
feedcd5
to
92b9ea1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few more comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the recent changes again and now everything now appears to be working as expected.
Reads default SDK from default gradle config now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this is good to go. I would appreciate reviews of my last changes though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The code changes LGTM.
- I tested various settings to confirmed that the config file was updated or reverted to defaults.
- I ran a build test.
- I verified the built APK contained the SDK targets. With and without changes.
Should have been part of apache#1212
Should have been part of #1212
It is a bad idea to unify these settings. Target SDK is a runtime setting which controls the level of backward compatibility fixes that Android is applying to the app. Compile SDK controls which declarations are being used to compile the code. They're separate things. You can still use features newer from API levels newer than your 'target SDK' setting, while keeping backward-compatible behaviour for the older parts of your app (or libraries) that you haven't upgraded yet. I realise this is a bit academic for apps on the Play Store, because Google require Target SDK = 30, from November 2021, even for updates to older apps. However, for anyone doing private distribution, including Managed Play Store, forcing an update to the target SDK in order to change the compile SDK is unnecessary. I'm not sure why you'd want to set the compile SDK lower than the target SDK, though. My line-of-business app, using cordova-android 6.4, currently uses compile SDK 26, to pick up support for adaptive icons, but target SDK 23, because we've not fixed any compatibility issues later than Marshmallow. I don't want to have to suddenly fix Android 11 compat issues, such as scoped storage enforcement, when upgrading to cordova-android 10. |
* enhancement: Control SDK versions and other default projects in one place * fix: target/compile sdk usage * refactor: cleanup gradle process * chore: cleanup and remove unused changes * chore: remove more unneeded FILE_PATH * chore: fix lint error * revert change intended to be part of a different PR * chore: apply changes to revert to fit new changes * fix: Ensure proper types * breaking: Removed TempateFile class * Replaced the one and only usage of it with the properties-parser editor. * Breaking change because we are converting a method into an asynchronous method. * refactor: Use the sync version of properties editor * Gh 1178 fix sdk use gradlearg fix (apache#2) * fix: readd gradleArg support * fix: variable name * refactor: remove unused mock variables * Update bin/templates/cordova/lib/builders/ProjectBuilder.js * Update bin/lib/create.js * fix: const naming (review suggestion) * fix: use defaults for framework building * chore: apply review suggestion * chore: rename config.json & defaults.json (review suggestions) * refactor: updateUserProjectGradleConfig method * refactor: minor changes in updateUserProjectGradleConfig * refactor: major changes in updateUserProjectGradleConfig * fix: wrong handling of missing preferences * fix: usage of undefined this * fix(create.spec): mocking of getPreference * test(check_reqs): reduce diff size * refactor: add wrapper to load gradle config defaults * fix(check_reqs): get_target * Reads default SDK from default gradle config now * fix(check_reqs.spec): return correct types from mocks * revert to using get_target in create * fix: e2e test Co-authored-by: Erisu <ellis.bryan@gmail.com> Co-authored-by: Raphael von der Grün <raphinesse@gmail.com>
Should have been part of apache#1212
Platforms affected
Android
Motivation and Context
Fixes #1178
Depends on #1211
The original target SDK fix PR didn't actually solve problem. This is because the framework and the compile SDK did not change based on the
android-targetSdkVersion
preference, resulting the default API to be downloaded and used, despite the target SDK change.Description
This is a breaking change because this PR replaces the
cdkTargetSdkVersion
andcdvCompileSdkVersion
with a new variable,cdvSdkVersion
, which theandroid-targetSdkVersion
sets.cdvSdkVersion
will control the androidtarget
API, as well as thetarget SDK
andcompile SDK
settings of the android project.Testing
npm test & manual testing. If you remove all platform APIs, and set
android-targetSdkVersion
to 29 you should see:Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)