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
refactor(android): build with gradle #11339
Conversation
- Replaced "ant" with "gradle" when building the Titanium SDK and Titanium apps. - Dropped "ant" build tool requirement. No longer used. - Updated min Android build-tools requirement from 25.0.0 to 28.0.3. * This is the min version required by Android gradle tool. - Now building Titanium as an AAR instead of individual JARs. * Core modules no longer built as separate JARs, but 1 monolitch JAR internally. - Replaced SDK's internal "android/TitaniumTest" project with "android/app" project. - Removed all Google library JARs and res files and replaced with gradle/maven repo references. - Titanium's generated "build.properties" moved from JAR resources to APK assets. - No longer post-fixing hash to app's res/drawable image files. Now stored/loaded as-is. - Removed res/values/strings.xml key "app_name" from all Titanium libraries. * This should only be defined by the app project. - Optimized @Kroll annotation process "kroll-apt". * Now only executed once during SDK build. (Old behavior loaded it 3 times.) * Now generates C++ V8 binding files in addition to binding JSON file. - Fixed TiUILabel to not access private API isSingleLine() when targeting Android Q. - Fixed C++ compiler errors and asserts when doing a "debug" build. - Removed "-a" API Level command line arg support from "node scons" build tools. * API Level is configured in "android/titanium/build.gradle" file. - Removed node module dependencies: * appc-aar-tools * archiver
- C/C++ makefile would fail during a clean if V8 library hasn't be downloaded yet. - Now downloads V8 when doing a "clean" or "build".
- Rewrote AndroidManifest.xml file merge handling. * Deleted "android/cli/lib/AndroidManifest.js" file. * Replaced with new "android/cli/lib/android-manifest.js" file. * Now blindly adds any XML element/attribute app developer sets. We no longer filter out nodes we don't know. (Future proof.) * Now supports "tools:" attributes to replace/remove XML elements/attributes. * Now auto-adds "tools:replace" attributes if "tiapp.xml" file's attributes collides with library's defined attributes. Avoids build failures. * Now preserves order of XML elements defined by app developer. This is important when using "tools:remove" feature. * Now inserts/merges <uses-permission/> elements above <application/> element to avoid gradle linting warning. - Added new "ti.constants.gradle" file: * Defines library versions used by Titanium. To be referenced by SDK builds, app builds, and module builds. * Defines manifest placeholder "tiActivityConfigChanges" which populates "android:configChanges" in <activity/> element. * Used by SDK builds, app builds, and module builds. - Added support for legacy manifest placeholder ${localApplicationId}. * Only used by "ti.zdetection" modules. Needed or else a gradle build failure will occur. - Improved error handling of build. Especially for unhandled promise rejections. - Modified some Android app build tasks to be done in parallel via Promise.all(). - Dropped support for appc config option "android.mergeCustomAndroidManifest". * Must use XML "tools:remove" or "tools:removeAll" attributes instead which is Google's equivalent feature.
- Added Android module "Resources" folder support. * Copies these files to APK "assets/Resources" folder. - Fixed app build failures when module manifest field contains double quotes. (Now properly escaped.)
- Change was lost while merging with gradle changes. Re-integrated the feature.
appc.subprocess.run('appc', [ '-q', 'config', 'get', 'proxyServer' ], runOptions, (exitCode, out) => { | ||
try { | ||
if (!exitCode && out && (out.length > 0)) { | ||
proxyUrl = url.parse(out.trim()); |
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.
⚠️ android/cli/lib/gradle-wrapper.js line 214 – 'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead. (node/no-deprecated-api)
Dependencies removed: |
- Jenkins build provides Android SDK/NDK paths when doing "node scons build", but not for "node scons package". Was causing build failure. - Modified to be more lenient and allow build to continue if Android "local.properties" file was already generated. (Logs warning instead.)
- Appcelerator Studio is hardcoded to find JS file in "build/android/assets" directory when debugging an Alloy project. * Caused by changing "assets" directory to "ti-assets" for gradle. Changed it back to "assets".
- Restored old behavior where we did not allow app dev's "AndroidManifest.xml" to override a Titanium <activity/> "android:configChanges" attribute. * Change was lost when changing build system to gradle.
- Now extracts Titanium C/C++ *.so libraries from AAR after gradle publishing step. * Unfortunately, Google does not provide an official means of changing the output directory for built *.so files.
So to review what we discussed on Teams/call. There's a mismatch in that the app's build.gradle file is specifying a dependency on
|
- iOS' logged errors during clean was causing Jenkins to fail the build. Now ignored.
- C/C++ makefile $(shell) command fails on Windows if built with "-n" dry-run flag. * Dry-run does not actually build anything and only fetches tasks to be completed. So, modified to skip fetch V8 source/lib files. * Thanks goes to Gary Mathews for isolating this.
- Added new environment variable TI_SDK_BUILD_REQUIRES_V8_SNAPSHOTS. * When set, will purposely trigger a build failure if failed to generate V8 snapshot C++ header file. (No fallbacks.) * Set by SDK build scripts under "titanium_mobile/build" directory. * Idea is to not let Jenkins release SDK builds missing V8 snapshots. But okay to use fallback for local Android Studio builds. - Cleaned up build scripts.
- No longer needed due to TIMOB-26910 which moved them to APK "assets" or "res" folders instead as an optimization.
- Now checks if environment variable TI_SDK_BUILD_REQUIRES_V8_SNAPSHOTS before "node scons" build overwrites it.
- Would cause build failures if target API Level was less than 26.
- Will use "en-US" language fallback in case "en" is missing. Minimizes gradle build warnings.
- Titanium's "kroll-apt.jar" annotation processor was not accepting all Kroll annotations defined, causing harmless errors to be logged.
- Removed usage of $(shell) in makefile which caused build failures on Windows for dry-run builds. * Dry-runs are needed to make C/C++ intellisense work in Android Studio. Used to pick up headers and libraries. - Now generates a git-ignored "V8Settings.mk" file storing version/mode of V8 to be used. Is included-in by main V8 makefile. - Added gradle incremental task which updates "V8Settings.mk" when "package.json" V8 settings change or if makefile is missing.
Please do not merge until Win android FR is done. FR Passed for MAC android. Ran below checks using Studio & CLI
I will add more if I remember something later ....... |
@jquick-axway When this PR is eventually ready to merge, what is your expectation for the merge itself? i.e. do you plan to do a lot of rebasing locally to clean it all up and rebase on top of tip of On larger PRs I tend to push commits until the CR is done and then manually rebase interactively (locally) to squash down to a smaller more coherent set of commits that could be rebased onto master. |
@sgtcoolguy, I'd rather we merge it as-is. I'm not a fan of squashing commits... unless the prior commits were horribly broken (in this case they're not). In fact, I purposely split some of my changes into separate commits so that they can be easily understood from a history/blame perspective. |
FR Passed on windows machine as well running both android device and emulators. |
@lokeshchdhry FYI
because the file name is actually |
@drauggres, yeah, I see the issue. Thanks. From looking at the Titanium The difference was that the old build script would log the following warning and carry on. The negative impact being that the Facebook APIs won't work since it'll fail to include the JAR. (This is bad.)
Our new build script rightfully logs it as an error now. |
JIRA:
Hyperloop Warning:
This PR will temporarily break hyperloop. Once this PR has been merged, we can then rebuild hyperloop module with gradle via the following private hyperloop PR...
tidev/hyperloop.next#329.
App Build Time Improvements:
Benchmarked with kitchensink-v2 on a 15" MacBook Pro 2015 with a solid state drive.
Summary of Changes:
titanium_mobile/android
directory in Android Studio.titanium_mobile/android
projectTitaniumTest
withapp
..so
libraries for asserts and debug logging.tools:
attributes. See link./platform/android/build.gradle
file for defining dependencies.res/drawable
image files. Now stored as-is.build.android.requestResourcesDirPaths
. To be used by plugins/modules (such as hyperloop) to add additional "Resources" files to app build../platform/android/AndroidManifest.xml
file.android.mergeCustomAndroidManifest
.tools:remove
ortools:removeAll
attributes instead which is Google's equivalent feature.KitchenSink Test:
Test the below on Mac and Windows.
APK Signature Scheme v2 Test:
true
for both v1 and v2 signatures.(Note that v3 should be
false
. Not currently supported.)"AndroidManifest.xml" Error Handling Test:
Custom "build.gradle" Test:
app.js
to the project.build.gradle
file to project's./platform/android
folder.@@@ [build.gradle] JavaCompile.doFirst
./Resources/app.js
./platform/android/build.gradle