Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(android): build with gradle (#11339)
* refactor(android): build with gradle - 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 * refactor(android): updated git-ignore list for gradle * refactor(android): moved kroll-apt files to gradle std folders * refactor(android): modified SDK to download V8 during a clean - 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". * refactor(android): rewrote manifest merge for gradle - 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. * refactor(android): build modules with gradle - 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.) * refactor(android): re-integrated "cach.json" feature - Change was lost while merging with gradle changes. Re-integrated the feature. * refactor(android): finished merging "master" into TIMOB-19300 * refactor(android): resolved linting issues for TIMOB-19300 * fix(android): sdk/ndk casing issue in SDK build script * refactor(android): allow SDK build if "local.properties" file exists - 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.) * fix(android): can't debug Alloy device builds - 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". * refactor(android): prevent <activity/> configChanges override - 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. * refactor(android): native *.so lib packaging - 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. * fix(android): titanium sdk version referencing in gradle * chore(android): added cli AndroidManfiest test script * chore(android): add NDK side-by-side detection for SDK builds * refactor(android): made transpile/snapshot a gradle prebuild step - Moved snapshot handling code out of "scons build" and added as gradle Titanium library prebuild step. - Removed old copy of Titanium "common JS files from SDK's test app. * Now uses current "common" folder's files instead. * Test "app" supports snapshot if built on Mac. Otherwise uses transpiled/rolled-up "ti.main.js" instead. - Added "incremental" transpile/polyfill/snapshot support of "titanium_mobile/common/Resources" JS files. * Only re-runs task if JS files were changed/added/removed or if output snapshot C++ header is missing. * refactor(android): added v8 snapshot fault tolerance - macOS Catalina doesn't support running x86 apps, preventing x86 V8 snapshot from being made. * Modified to not fail the build. If at least 1 snapshot failed, then fallback to using "ti.main.js" instead. * refactor(android): sdk V8 snapshot changes - Removed default "V8Snapshots.h" file. * I did remove it before, but "node scons package" code reverted the file. - Modified "Generating snapshot blob" log message to not be a warning. * chore(android): additional gradle build changes - Added build hook "build.android.requestResourcesDirPaths". * Allows plugins to add their own "Resources" directory tree to app build. * Used by hyperloop to add its generated JS files which interop with Java classes. * Event data.args[0] provides an array for paths to be added to. - Fixed bug where module Java package names not containing a '.' will fail to build. * This is a new restriction from Google's build system. * Will now prefix "ti." to package name if missing a '.'. - Modified gradle JS code's async functions to not directly return promises. - Modified app build to support optional "build.gradle" file under "./platform/android". * Mostly intended for hyperloop, but can be used for other purposes as well. - Fixed SDK build failure on Windows that happens in NDK build step. * Now escapes paths with backslashes for NDK arguments. * Now tells NDK to use short command line strings on Windows. (Was exceeding max chars.) * chore(android): re-added server V8 snapshot handling * chore: have jenkins do a clean before build * fix(ios): jenkins build failure caused by new clean step - iOS' logged errors during clean was causing Jenkins to fail the build. Now ignored. * chore(android): resolved SDK build failures on Windows - 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. * refactor(android): improved cloud v8 snapshot handling - 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. * chore(android): removed JAR resources reference in SDK - No longer needed due to TIMOB-26910 which moved them to APK "assets" or "res" folders instead as an optimization. * chore(android): made NDK optional for app builds * chore(android): allow SDK build system to override snapshot handling - Now checks if environment variable TI_SDK_BUILD_REQUIRES_V8_SNAPSHOTS before "node scons" build overwrites it. * fix(android): gradle module path issues on windows * fix(android): don't compile with target api level - Would cause build failures if target API Level was less than 26. * chore(android): added i18n fallback for "en-US" - Will use "en-US" language fallback in case "en" is missing. Minimizes gradle build warnings. * fix(android): module build logs errors for unused annotations - Titanium's "kroll-apt.jar" annotation processor was not accepting all Kroll annotations defined, causing harmless errors to be logged. * chore(android): v8 makefile improvements - 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. Co-authored-by: Christopher Williams <chris.a.williams@gmail.com> Co-authored-by: Lokesh Choudhary <lchoudhary@axway.com>
- Loading branch information