diff --git a/.github/workflows/npm_release.yml b/.github/workflows/npm_release.yml index fa8c37e63..43a4c76b7 100644 --- a/.github/workflows/npm_release.yml +++ b/.github/workflows/npm_release.yml @@ -3,21 +3,20 @@ on: branches: - main tags: - - 'v*' + - "v*" env: NPM_TAG: "next" EMULATOR_NAME: "runtime-emu" - NDK_VERSION: r21b - ANDROID_API: 29 + NDK_VERSION: r27 + ANDROID_API: 33 ANDROID_ABI: x86_64 - NDK_ARCH: darwin-x86_64 - + NDK_ARCH: darwin jobs: build: name: Build - runs-on: macos-latest + runs-on: macos-13 outputs: npm_version: ${{ steps.npm_version_output.outputs.NPM_VERSION }} npm_tag: ${{ steps.npm_version_output.outputs.NPM_TAG }} @@ -28,12 +27,12 @@ jobs: submodules: true - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 22 registry-url: "https://registry.npmjs.org" - uses: actions/setup-java@v3 with: distribution: "temurin" - java-version: "17" + java-version: "21" cache: gradle - name: Setup Android SDK uses: android-actions/setup-android@v2 @@ -74,13 +73,19 @@ jobs: - name: Build npm package run: ./gradlew -PgitCommitVersion=${{ github.sha }} -PnoCCache --stacktrace - name: Upload npm package artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: npm-package path: dist/nativescript-android-${{steps.npm_version_output.outputs.NPM_VERSION}}.tgz + - name: Upload debug symbols + uses: actions/upload-artifact@v4 + with: + name: debug-symbols + path: test-app/runtime/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/* + test: name: Test - runs-on: macos-latest + runs-on: macos-13 needs: build steps: - uses: actions/checkout@v3 @@ -88,12 +93,12 @@ jobs: submodules: true - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 22 registry-url: "https://registry.npmjs.org" - uses: actions/setup-java@v3 with: distribution: "temurin" - java-version: "17" + java-version: "21" cache: gradle - name: Setup Android SDK uses: android-actions/setup-android@v2 @@ -131,17 +136,17 @@ jobs: - build - test permissions: - contents: read - id-token: write + contents: read + id-token: write env: NPM_VERSION: ${{needs.build.outputs.npm_version}} NPM_TAG: ${{needs.build.outputs.npm_tag}} steps: - uses: actions/setup-node@v3 with: - node-version: 18 - registry-url: 'https://registry.npmjs.org' - - uses: actions/download-artifact@v3 + node-version: 22 + registry-url: "https://registry.npmjs.org" + - uses: actions/download-artifact@v4 with: name: npm-package path: dist @@ -168,16 +173,24 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 22 - name: Setup run: npm install - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: npm-package path: dist + - uses: actions/download-artifact@v4 + with: + name: debug-symbols + path: dist/debug-symbols + - name: Zip debug symbols + working-directory: dist/debug-symbols + run: zip -r debug-symbols.zip . - name: Partial Changelog run: npx conventional-changelog -p angular -r2 > body.md - uses: ncipollo/release-action@v1 with: - artifacts: "dist/nativescript-android-*.tgz" + artifacts: "dist/nativescript-android-*.tgz,dist/debug-symbols/debug-symbols.zip" bodyFile: "body.md" + prerelease: ${{needs.build.outputs.npm_tag != 'latest'}} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index a2c844c83..de0f75728 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -4,16 +4,16 @@ on: env: NPM_TAG: "pr" EMULATOR_NAME: "runtime-emu" - NDK_VERSION: r21b - ANDROID_API: 29 + NDK_VERSION: r27 + ANDROID_API: 33 ANDROID_ABI: x86_64 - NDK_ARCH: darwin-x86_64 + NDK_ARCH: darwin jobs: build: name: Build - runs-on: macos-latest + runs-on: macos-13 outputs: npm_version: ${{ steps.npm_version_output.outputs.NPM_VERSION }} npm_tag: ${{ steps.npm_version_output.outputs.NPM_TAG }} @@ -24,12 +24,12 @@ jobs: submodules: true - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 22 registry-url: "https://registry.npmjs.org" - uses: actions/setup-java@v3 with: distribution: "temurin" - java-version: "17" + java-version: "21" cache: gradle - name: Setup Android SDK uses: android-actions/setup-android@v2 @@ -70,13 +70,18 @@ jobs: - name: Build npm package run: ./gradlew -PgitCommitVersion=${{ github.sha }} -PnoCCache --stacktrace - name: Upload npm package artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: npm-package path: dist/nativescript-android-${{steps.npm_version_output.outputs.NPM_VERSION}}.tgz + - name: Upload debug symbols + uses: actions/upload-artifact@v4 + with: + name: debug-symbols + path: test-app/runtime/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib/* test: name: Test - runs-on: macos-latest + runs-on: macos-13 needs: build steps: - uses: actions/checkout@v3 @@ -84,12 +89,12 @@ jobs: submodules: true - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 22 registry-url: "https://registry.npmjs.org" - uses: actions/setup-java@v3 with: distribution: "temurin" - java-version: "17" + java-version: "21" cache: gradle - name: Setup Android SDK uses: android-actions/setup-android@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d5ba6ee..4b6700151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,180 @@ +# [8.9.0](https://github.com/NativeScript/android/compare/v8.8.6...v8.9.0) (2025-02-26) + + +### Bug Fixes + +* inner type should net be set when companion object is defined as function ([#1831](https://github.com/NativeScript/android/issues/1831)) ([e293636](https://github.com/NativeScript/android/commit/e293636ed1e9277d608e3102b404f94539404fdf)) + + +### Features + +* Ada 3.1.1 ([3633aed](https://github.com/NativeScript/android/commit/3633aed8913c7b93757909a569bfb8ab225add13)) +* ada v3 ([#1830](https://github.com/NativeScript/android/issues/1830)) ([b31fc5f](https://github.com/NativeScript/android/commit/b31fc5f7144b873981b8c7201d72baf26a6e79bc)) +* NDK 27 and Support for Java 21 ([#1819](https://github.com/NativeScript/android/issues/1819)) ([bec401c](https://github.com/NativeScript/android/commit/bec401c918942443bccab4e697cea2ccb843e603)) +* support 16 KB page sizes, gradle 8.5 ([#1818](https://github.com/NativeScript/android/issues/1818)) ([3423e6f](https://github.com/NativeScript/android/commit/3423e6ff05c5340f92eec46f8c8e996d78403860)) + + +### Performance Improvements + +* optimizations around generating JS classes from Metadata ([#1824](https://github.com/NativeScript/android/issues/1824)) ([f290ed2](https://github.com/NativeScript/android/commit/f290ed26da315ddefb56fa1acd212c6242ab976b)) + + + +## [8.8.6](https://github.com/NativeScript/android/compare/v8.8.5...v8.8.6) (2024-10-28) + + +### Bug Fixes + +* `exit(0)` causes ANR due to destroyed mutex ([#1820](https://github.com/NativeScript/android/issues/1820)) ([94ddb15](https://github.com/NativeScript/android/commit/94ddb159ccf368edebce76a8aa01d141d7297b1a)) +* gradle error when compileSdk or targetSdk is provided ([#1825](https://github.com/NativeScript/android/issues/1825)) ([a983931](https://github.com/NativeScript/android/commit/a983931cf5e9fcc7966a98a2f0ec4e24e040af5e)) +* **URL:** allow undefined 2nd args ([#1826](https://github.com/NativeScript/android/issues/1826)) ([2bab8f5](https://github.com/NativeScript/android/commit/2bab8f5be85c8764faafef4d6374dc8cfd257613)) + + + +## [8.8.5](https://github.com/NativeScript/android/compare/v8.8.4...v8.8.5) (2024-09-30) + + +### Bug Fixes + +* prevent metadata offset overflow into array space and convert shorts to uints before addition ([9cfc349](https://github.com/NativeScript/android/commit/9cfc3493017243948b043a51f68b7c7bcab1e6b9)) + + + +## [8.8.4](https://github.com/NativeScript/android/compare/v8.8.3...v8.8.4) (2024-09-06) + + +### Bug Fixes + +* ensure same mtime for js and code cache to prevent loading old code caches ([#1822](https://github.com/NativeScript/android/issues/1822)) ([3d6e101](https://github.com/NativeScript/android/commit/3d6e10115227ad556e5bbe1764217716ab5bdac7)) + + + +## [8.8.3](https://github.com/NativeScript/android/compare/v8.8.2...v8.8.3) (2024-09-02) + + +### Bug Fixes + +* generate correct metadata when overflowing signed short values ([#1821](https://github.com/NativeScript/android/issues/1821)) ([c9fac4b](https://github.com/NativeScript/android/commit/c9fac4b19a952d4df651d3d6a8b0fa9c50f7c7db)) + + + +## [8.8.2](https://github.com/NativeScript/android/compare/v8.8.1...v8.8.2) (2024-07-22) + + +### Bug Fixes + +* config with multiple bundle ids ([#1816](https://github.com/NativeScript/android/issues/1816)) ([cdcfee2](https://github.com/NativeScript/android/commit/cdcfee266617472ac7f3ac59742b858ad093e46b)) + + + +## [8.8.1](https://github.com/NativeScript/android/compare/v8.8.0...v8.8.1) (2024-07-10) + + +### Features + +* Ada 2.9 ([#1814](https://github.com/NativeScript/android/issues/1814)) ([91accf9](https://github.com/NativeScript/android/commit/91accf9be1caf9ad2accb80bf9aca18efe4dd75a)) + + + +# [8.8.0](https://github.com/NativeScript/android/compare/v8.7.0...v8.8.0) (2024-07-09) + + +### Bug Fixes + +* correctly load ts_helpers.js in workers ([#1798](https://github.com/NativeScript/android/issues/1798)) ([31f8501](https://github.com/NativeScript/android/commit/31f8501bb902815cfed8e1cd123fe8b6de2cb757)) + + +### Features + +* Kotlin 2 + Gradle 8+ ([#1812](https://github.com/NativeScript/android/issues/1812)) ([d4b7164](https://github.com/NativeScript/android/commit/d4b716427934ebb4387a04842561d5b5d0e1fa3d)) + + + +# [8.7.0](https://github.com/NativeScript/android/compare/v8.7.0-rc.3...v8.7.0) (2024-04-08) + + + +# [8.7.0-rc.3](https://github.com/NativeScript/android/compare/v8.6.2...v8.7.0-rc.3) (2024-04-08) + + +### Bug Fixes + +* devtools namespace usage ([#1810](https://github.com/NativeScript/android/issues/1810)) ([5aaac57](https://github.com/NativeScript/android/commit/5aaac5788ff9abf1c043817e87c8e03eb61907c0)) +* dts-generator.jar path ([1120a32](https://github.com/NativeScript/android/commit/1120a3258d53f83b7b4dfe7e505234e2b0d6cd2b)) +* inspector and globals ([#1811](https://github.com/NativeScript/android/issues/1811)) ([79ebd18](https://github.com/NativeScript/android/commit/79ebd18f308cd86fa98784f14b5c3f5ac39d8c5f)) + + +### Features + +* bump ndk to r23c ([#1803](https://github.com/NativeScript/android/issues/1803)) ([3894959](https://github.com/NativeScript/android/commit/3894959e0b4fe31f61cfd9fa70d5e2b04a0f36ac)) +* devtools element/network inspectors ([#1808](https://github.com/NativeScript/android/issues/1808)) ([1470796](https://github.com/NativeScript/android/commit/1470796dc506f0d01e94fe117119dc217ff8c909)) +* migrate to faster maps and use runtime context ([#1793](https://github.com/NativeScript/android/issues/1793)) ([b248dc4](https://github.com/NativeScript/android/commit/b248dc4038d0c1a6af420447c713bc968431f97e)) +* update libzip to 1.10.1 ([#1805](https://github.com/NativeScript/android/issues/1805)) ([ee2e3e0](https://github.com/NativeScript/android/commit/ee2e3e0b87caf3cff4784f1464dd51b2923c6861)) +* use node module bindings like the iOS runtime ([#1795](https://github.com/NativeScript/android/issues/1795)) ([643958b](https://github.com/NativeScript/android/commit/643958b6a4c3698567edde3fd03052873b2644dc)) +* **WinterCG:** URL & URLSearchParams ([#1801](https://github.com/NativeScript/android/issues/1801)) ([4f3a0d7](https://github.com/NativeScript/android/commit/4f3a0d7f2de5f899779bd0fe9081390e6c4d24b2)) + + +### Reverts + +* Version.h changes ([9faa25d](https://github.com/NativeScript/android/commit/9faa25dda197d3da4f694ea59208309bb02e529c)) + + + +## [8.6.2](https://github.com/NativeScript/android/compare/v8.6.1...v8.6.2) (2023-10-10) + + + +## [8.6.1](https://github.com/NativeScript/android/compare/v8.6.0...v8.6.1) (2023-10-10) + + +### Bug Fixes + +* copy drawables ([4ff92cb](https://github.com/NativeScript/android/commit/4ff92cb32a954be4c3d32c302e301cef0a4b72a6)) + + + +# [8.6.0](https://github.com/NativeScript/android/compare/v8.5.3...v8.6.0) (2023-10-06) + + +### Bug Fixes + +* make jar files readonly prior to loading ([#1790](https://github.com/NativeScript/android/issues/1790)) ([2bcdaf0](https://github.com/NativeScript/android/commit/2bcdaf01fb850db4a982c22c2d792f9493a2a7fa)) +* only use project jar files if they are linked ([d23ca94](https://github.com/NativeScript/android/commit/d23ca94ba7c660b26224c57ba6f22085aa99f95c)) +* revert namespace change as to not break existing projects ([8b7b59d](https://github.com/NativeScript/android/commit/8b7b59d23d926b696bde3c1031cf3a842a24133d)) + + +### Features + +* improved error activity ui ([#1776](https://github.com/NativeScript/android/issues/1776)) ([ee3e354](https://github.com/NativeScript/android/commit/ee3e354f1bec89268daf93086aa6dd24898677b9)) +* upgrade client gradle version ([c778c0d](https://github.com/NativeScript/android/commit/c778c0d238c4ba44390f786ba06ab8e51ffb2c97)) + +## [8.5.4](https://github.com/NativeScript/android/compare/v8.5.3...v8.5.4) (2023-09-27) + + +### Bug Fixes + +* make jar files readonly prior to loading ([#1790](https://github.com/NativeScript/android/issues/1790)) ([14a932a](https://github.com/NativeScript/android/commit/14a932ad2d62c94f2f4e139125835da760dcdd58)) + + +## [8.5.3](https://github.com/NativeScript/android/compare/v8.5.2...v8.5.3) (2023-09-22) + + +### Bug Fixes + +* resolve __postFrameCallback crash on re-scheduling ([6a533ce](https://github.com/NativeScript/android/commit/6a533ce58b22b163d888c51f203be2ef3aa98347)) + + + +## [8.5.2](https://github.com/NativeScript/android/compare/v8.5.1...v8.5.2) (2023-08-31) + + +### Bug Fixes + +* __runOnMainThread erase iterator before it can be invalidated ([e811484](https://github.com/NativeScript/android/commit/e81148409046957fceb07b14394baa5bc055286d)) +* pull js stack trace from wrapped NativeScriptExceptions ([#1774](https://github.com/NativeScript/android/issues/1774)) ([52b7fa2](https://github.com/NativeScript/android/commit/52b7fa242cb4582701dcebf97aa0f6e0400bcb1a)) + + + ## [8.5.1](https://github.com/NativeScript/android/compare/v8.5.0...v8.5.1) (2023-07-24) diff --git a/build.gradle b/build.gradle index 24182cc94..93be4ace6 100644 --- a/build.gradle +++ b/build.gradle @@ -261,11 +261,11 @@ task copyFilesToProjectTemeplate { into "$DIST_FRAMEWORK_PATH/app/src/main/java/com/tns/internal" } copy { - from "$BUILD_TOOLS_PATH/static-binding-generator.jar" + from "$BUILD_TOOLS_PATH/static-binding-generator/build/libs/static-binding-generator.jar" into "$DIST_FRAMEWORK_PATH/build-tools" } copy { - from "$BUILD_TOOLS_PATH/dts-generator.jar" + from "$BUILD_TOOLS_PATH/android-dts-generator/dts-generator/build/libs/dts-generator.jar" into "$DIST_FRAMEWORK_PATH/build-tools" } copy { @@ -273,7 +273,7 @@ task copyFilesToProjectTemeplate { into "$DIST_FRAMEWORK_PATH/build-tools/jsparser" } copy { - from "$BUILD_TOOLS_PATH/android-metadata-generator.jar" + from "$BUILD_TOOLS_PATH/android-metadata-generator/build/libs/android-metadata-generator.jar" into "$DIST_FRAMEWORK_PATH/build-tools" } copy { diff --git a/build.sh b/build.sh index b176b1195..2f42b49c9 100755 --- a/build.sh +++ b/build.sh @@ -50,33 +50,34 @@ fi ./gradlew runSbgTests for emulator in $listOfEmulators; do - echo "Start emulator $emulator" - $ANDROID_HOME/emulator/emulator -avd ${emulator} -verbose -wipe-data -gpu on& - find ~/.android/avd/${emulator}.avd -type f -name 'config.ini' -exec cat {} + + echo "Start emulator $emulator" + $ANDROID_HOME/emulator/emulator -avd ${emulator} -verbose -wipe-data -gpu on& + find ~/.android/avd/${emulator}.avd -type f -name 'config.ini' -exec cat {} + - echo "Run Android Runtime unit tests for $emulator" - $ANDROID_HOME/platform-tools/adb wait-for-device - $ANDROID_HOME/platform-tools/adb -s emulator-5554 logcat -c - $ANDROID_HOME/platform-tools/adb -s emulator-5554 logcat > consoleLog.txt& - $ANDROID_HOME/platform-tools/adb -s emulator-5554 logcat > consoleLog$emulator.txt& + echo "Run Android Runtime unit tests for $emulator" + $ANDROID_HOME/platform-tools/adb wait-for-device + $ANDROID_HOME/platform-tools/adb -s emulator-5554 logcat -c + $ANDROID_HOME/platform-tools/adb -s emulator-5554 logcat > consoleLog.txt& + $ANDROID_HOME/platform-tools/adb -s emulator-5554 logcat > consoleLog$emulator.txt& - if [ "$1" != 'unit_tests_only' ]; then - ./gradlew runtests - else - ./gradlew runtests -PonlyX86 - fi + if [ "$1" != 'unit_tests_only' ]; then + ./gradlew runtests + else + ./gradlew runtests -PonlyX86 + fi - echo "Rename unit test result" - ( - cd ./test-app/dist - mv android_unit_test_results.xml $emulator.xml - ) + echo "Rename unit test result" + ( + cd ./test-app/dist + mv android_unit_test_results.xml $emulator.xml + ) - echo "Stopping running emulators" - for KILLPID in `ps ax | grep 'emulator' | grep -v 'grep' | awk ' { print $1;}'`; do kill -9 $KILLPID; done - for KILLPID in `ps ax | grep 'qemu' | grep -v 'grep' | awk ' { print $1;}'`; do kill -9 $KILLPID; done - for KILLPID in `ps ax | grep 'adb' | grep -v 'grep' | awk ' { print $1;}'`; do kill -9 $KILLPID; done + echo "Stopping running emulators" + for KILLPID in `ps ax | grep 'emulator' | grep -v 'grep' | awk ' { print $1;}'`; do kill -9 $KILLPID; done + for KILLPID in `ps ax | grep 'qemu' | grep -v 'grep' | awk ' { print $1;}'`; do kill -9 $KILLPID; done + for KILLPID in `ps ax | grep 'adb' | grep -v 'grep' | awk ' { print $1;}'`; do kill -9 $KILLPID; done done echo $cwd cd $cwd + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7a3265ee9..2c3521197 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 69bc70d1f..09523c0e5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Tue May 12 20:24:09 CEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip \ No newline at end of file diff --git a/gradlew b/gradlew index cccdd3d51..f5feea6d6 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,130 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,92 +133,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f9553162f..9d21a2183 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,22 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,25 +27,29 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -35,48 +57,36 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/package.json b/package.json index 294644ba5..60a7bd8fa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nativescript/android", "description": "NativeScript for Android using v8", - "version": "8.5.1", + "version": "8.9.1", "repository": { "type": "git", "url": "https://github.com/NativeScript/android.git" @@ -10,20 +10,20 @@ "**/*" ], "version_info": { - "v8": "8.3.110.9", - "gradle": "7.5", - "gradleAndroid": "7.3.0", - "ndk": "r21", - "ndkApiLevel": "22", - "minSdk": "17", - "compileSdk": "32", - "buildTools": "32.0.0", - "kotlin": "1.7.10" + "v8": "10.3.22.0", + "gradle": "8.7", + "gradleAndroid": "8.5.0", + "ndk": "r27", + "ndkApiLevel": "21", + "minSdk": "21", + "compileSdk": "35", + "buildTools": "35.0.0", + "kotlin": "2.0.0" }, "// this gradle key is here for backwards compatibility - we'll phase it out slowly...": "", "gradle": { - "version": "7.5", - "android": "7.3.0" + "version": "8.7", + "android": "8.5.0" }, "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", diff --git a/test-app/app/build.gradle b/test-app/app/build.gradle index d7bfd787b..ec5aea981 100644 --- a/test-app/app/build.gradle +++ b/test-app/app/build.gradle @@ -20,9 +20,8 @@ * -PappResourcesPath=[app_resources_path] */ - -import groovy.io.FileType import groovy.json.JsonSlurper +import groovy.xml.XmlSlurper import org.apache.commons.io.FileUtils import javax.inject.Inject @@ -30,26 +29,17 @@ import java.nio.file.Files import java.nio.file.Paths import java.nio.file.StandardCopyOption import java.security.MessageDigest - import java.util.jar.JarEntry import java.util.jar.JarFile import static org.gradle.internal.logging.text.StyledTextOutput.Style -import java.util.stream.Collectors; -import java.util.stream.Stream; - apply plugin: "com.android.application" apply from: "gradle-helpers/BuildToolTask.gradle" apply from: "gradle-helpers/CustomExecutionLogger.gradle" apply from: "gradle-helpers/AnalyticsCollector.gradle" - -def enableKotlin = (project.hasProperty("useKotlin") && project.useKotlin == "true") - -if (enableKotlin) { - apply plugin: 'kotlin-android' - apply plugin: 'kotlin-parcelize' -} +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-parcelize' def onlyX86 = project.hasProperty("onlyX86") if (onlyX86) { @@ -75,6 +65,7 @@ def SBG_BINDINGS_NAME = "sbg-bindings.txt" def SBG_INTERFACE_NAMES = "sbg-interface-names.txt" def INPUT_JS_DIR = "$projectDir/src/main/assets/app" def OUTPUT_JAVA_DIR = "$projectDir/src/main/java" +def APP_DIR = "$projectDir/src/main/assets/app" //metadata generator def MDG_OUTPUT_DIR = "mdg-output-dir.txt" @@ -86,9 +77,9 @@ def METADATA_JAVA_OUT = "mdg-java-out.txt" def pluginsJarLibraries = new LinkedList() def allJarLibraries = new LinkedList() -def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "${ns_default_kotlin_version}" } -def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : NS_DEFAULT_COMPILE_SDK_VERSION as int } -def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? targetSdk : NS_DEFAULT_COMPILE_SDK_VERSION as int } +def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk as int : NS_DEFAULT_COMPILE_SDK_VERSION as int } +def computeTargetSdkVersion = { -> project.hasProperty("targetSdk") ? targetSdk as int : NS_DEFAULT_COMPILE_SDK_VERSION as int } +def computeMinSdkVersion = { -> project.hasProperty("minSdk") ? minSdk : NS_DEFAULT_MIN_SDK_VERSION as int } def computeBuildToolsVersion = { -> project.hasProperty("buildToolsVersion") ? buildToolsVersion : NS_DEFAULT_BUILD_TOOLS_VERSION as String } @@ -98,7 +89,7 @@ def enableVerboseMDG = project.gradle.startParameter.logLevel.name() == 'DEBUG' def analyticsFilePath = "$rootDir/analytics/build-statistics.json" def analyticsCollector = project.ext.AnalyticsCollector.withOutputPath(analyticsFilePath) if (enableAnalytics) { - analyticsCollector.markUseKotlinPropertyInApp(enableKotlin) + analyticsCollector.markUseKotlinPropertyInApp(true) analyticsCollector.writeAnalyticsFile() } @@ -185,25 +176,52 @@ def setAppIdentifier = { -> if (appIdentifier) { project.ext.nsApplicationIdentifier = appIdentifier android.defaultConfig.applicationId = appIdentifier + android.namespace = appIdentifier + } + } +} + +def computeNamespace = { -> + def appPackageJsonFile = file("${APP_DIR}/$PACKAGE_JSON") + + if (appPackageJsonFile.exists()) { + def content = appPackageJsonFile.getText("UTF-8") + + def jsonSlurper = new JsonSlurper() + def packageJsonMap = jsonSlurper.parseText(content) + + def appIdentifier = "" + + if (packageJsonMap) { + if (packageJsonMap.android && packageJsonMap.android.id) { + appIdentifier = packageJsonMap.android.id + } else if (packageJsonMap.id) { + appIdentifier = packageJsonMap.id + } + } + + if (appIdentifier) { + return appIdentifier } } + return "com.tns.testapplication" } android { + namespace computeNamespace() + applyBeforePluginGradleConfiguration() - if (enableKotlin) { - kotlinOptions { - jvmTarget = '1.8' - } + kotlinOptions { + jvmTarget = '17' } - compileSdkVersion computeCompileSdkVersion() - buildToolsVersion computeBuildToolsVersion() + compileSdk computeCompileSdkVersion() + buildToolsVersion = computeBuildToolsVersion() defaultConfig { def manifest = new XmlSlurper().parse(file(android.sourceSets.main.manifest.srcFile)) - def minSdkVer = manifest."uses-sdk"."@android:minSdkVersion".text() ?: NS_DEFAULT_MIN_SDK_VERSION + def minSdkVer = manifest."uses-sdk"."@android:minSdkVersion".text() ?: computeMinSdkVersion() minSdkVersion minSdkVer targetSdkVersion computeTargetSdkVersion() ndk { @@ -216,8 +234,8 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } sourceSets.main { @@ -251,12 +269,12 @@ android { applyAppGradleConfiguration() def initializeMergedAssetsOutputPath = { -> - android.applicationVariants.all { variant -> + android.applicationVariants.configureEach { variant -> if (variant.buildType.name == project.selectedBuildType) { def task if (variant.metaClass.respondsTo(variant, "getMergeAssetsProvider")) { def provider = variant.getMergeAssetsProvider() - task = provider.get(); + task = provider.get() } else { // fallback for older android gradle plugin versions task = variant.getMergeAssets() @@ -264,7 +282,7 @@ android { for (File file : task.getOutputs().getFiles()) { if (!file.getPath().contains("${File.separator}incremental${File.separator}")) { project.ext.mergedAssetsOutputPath = file.getPath() - break; + break } } } @@ -394,18 +412,13 @@ dependencies { implementation project(':runtime') } - def kotlinVersion = computeKotlinVersion() - if (enableKotlin) { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" - } - } //////////////////////////////////////////////////////////////////////////////////// ///////////////////////////// CONFIGURATION PHASE ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// -task addDependenciesFromNativeScriptPlugins { +task 'addDependenciesFromNativeScriptPlugins' { nativescriptDependencies.each { dep -> def aarFiles = fileTree(dir: file("$rootDir/${dep.directory}/$PLATFORMS_ANDROID"), include: ["**/*.aar"]) aarFiles.each { aarFile -> @@ -426,7 +439,7 @@ task addDependenciesFromNativeScriptPlugins { } } -task addDependenciesFromAppResourcesLibraries { +task 'addDependenciesFromAppResourcesLibraries' { def appResourcesPath = getAppResourcesPath() def appResourcesLibraries = file("$appResourcesPath/Android/libs") if (appResourcesLibraries.exists()) { @@ -450,47 +463,22 @@ task addDependenciesFromAppResourcesLibraries { } if (failOnCompilationWarningsEnabled()) { - tasks.withType(JavaCompile) { + tasks.withType(JavaCompile).configureEach { options.compilerArgs << '-Xlint:all' << "-Werror" options.deprecation = true } } -tasks.whenTaskAdded({ DefaultTask currentTask -> - if (currentTask =~ /generate.+BuildConfig/) { - currentTask.finalizedBy(extractAllJars) - extractAllJars.finalizedBy(collectAllJars) - } - if (currentTask =~ /compile.+JavaWithJavac/) { - currentTask.dependsOn(runSbg) - currentTask.finalizedBy(buildMetadata) - } - - - if (currentTask =~ /compile.+Kotlin.+/) { - currentTask.dependsOn(runSbg) - currentTask.finalizedBy(buildMetadata) - } - - if (currentTask =~ /merge.*Assets/) { - currentTask.dependsOn(buildMetadata) - } - // ensure buildMetadata is done before R8 to allow custom proguard from metadata - if (currentTask =~ /minify.*WithR8/) { - currentTask.dependsOn(buildMetadata) - } - if (currentTask =~ /assemble.*Debug/ || currentTask =~ /assemble.*Release/) { - currentTask.finalizedBy("validateAppIdMatch") - } -}) //////////////////////////////////////////////////////////////////////////////////// -///////////////////////////// EXECUTUION PHASE ///////////////////////////////////// +///////////////////////////// EXECUTION PHASE ///////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// task runSbg(type: BuildToolTask) { dependsOn "collectAllJars" + def rootPath = "" if (!findProject(':static-binding-generator').is(null)) { + rootPath = Paths.get(project(':static-binding-generator').projectDir.path, "build/libs").toString() dependsOn ':static-binding-generator:jar' } @@ -499,10 +487,10 @@ task runSbg(type: BuildToolTask) { inputs.dir(extractedDependenciesDir) workingDir "$BUILD_TOOLS_PATH" - main "-jar" + mainClass = "-jar" def paramz = new ArrayList() - paramz.add("static-binding-generator.jar") + paramz.add(Paths.get(rootPath, "static-binding-generator.jar")) if (failOnCompilationWarningsEnabled()) { paramz.add("-show-deprecation-warnings") @@ -548,7 +536,7 @@ def explodeAar(File compileDependency, File outputDir) { } } -def md5(String string) { +static def md5(String string) { MessageDigest digest = MessageDigest.getInstance("MD5") digest.update(string.bytes) return new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') @@ -581,9 +569,9 @@ allprojects { def buildType = project.selectedBuildType def jars = [] def artifactType = Attribute.of('artifactType', String) - android.applicationVariants.all { variant -> + android.applicationVariants.configureEach { variant -> if (variant.buildType.name == buildType) { - variant.getCompileClasspath().each { fileDependency -> + variant.getCompileClasspath(null).each { fileDependency -> processJar(fileDependency, jars) } } @@ -601,7 +589,7 @@ def processJar(File jar, jars) { logger.debug("Creating dynamic task ${taskName}") // Add discovered jars as dependencies of cleanupAllJars. - // This is cruicial for cloud builds because they are different + // This is crucial for cloud builds because they are different // on each incremental build (as each time the gradle user home // directory is a randomly generated string) cleanupAllJars.inputs.files jar @@ -631,7 +619,7 @@ def processJar(File jar, jars) { } } -task cleanupAllJars { +task 'cleanupAllJars' { // We depend on the list of libs directories that might contain aar or jar files // and on the list of all discovered jars inputs.files(pluginDependencies) @@ -656,7 +644,7 @@ task cleanupAllJars { // Placeholder task which depends on all dynamically generated extraction tasks -task extractAllJars { +task 'extractAllJars' { dependsOn cleanupAllJars outputs.files extractAllJarsTimestamp @@ -665,7 +653,7 @@ task extractAllJars { } } -task collectAllJars { +task 'collectAllJars' { dependsOn extractAllJars description "gathers all paths to jar dependencies before building metadata with them" @@ -703,27 +691,31 @@ task collectAllJars { } } -task copyMetadataFilters(type: Copy) { - from "$rootDir/whitelist.mdg", "$rootDir/blacklist.mdg" - into "$BUILD_TOOLS_PATH" +task copyMetadataFilters { + outputs.files("$BUILD_TOOLS_PATH/whitelist.mdg", "$BUILD_TOOLS_PATH/blacklist.mdg") + // use an explicit copy task here because the copy task itselfs marks the whole built-tools as an output! + copy { + from file("$rootDir/whitelist.mdg"), file("$rootDir/blacklist.mdg") + into "$BUILD_TOOLS_PATH" + } } -task copyMetadata { +task 'copyMetadata' { doLast { copy { - from "$projectDir/src/main/assets/metadata" - into getMergedAssetsOutputPath() + "/metadata" + from "$projectDir/src/main/assets/metadata" + into getMergedAssetsOutputPath() + "/metadata" } } } def listf(String directoryName, ArrayList store) { - def directory = new File(directoryName); + def directory = new File(directoryName) - def resultList = new ArrayList(); + def resultList = new ArrayList() - def fList = directory.listFiles(); - resultList.addAll(Arrays.asList(fList)); + def fList = directory.listFiles() + resultList.addAll(Arrays.asList(fList)) for (File file : fList) { if (file.isFile()) { store.add(file) @@ -735,10 +727,173 @@ def listf(String directoryName, ArrayList store) { } task buildMetadata(type: BuildToolTask) { + def rootPath = "" if (!findProject(':android-metadata-generator').is(null)) { + rootPath = Paths.get(project(':android-metadata-generator').projectDir.path, "build/libs").toString() dependsOn ':android-metadata-generator:jar' } + + + android.applicationVariants.all { variant -> + def buildTypeName = variant.buildType.name.capitalize() + def mergeShadersTaskName = "merge${buildTypeName}Shaders" + def mergeShadersTask = tasks.findByName(mergeShadersTaskName) + + if (mergeShadersTask) { + dependsOn mergeShadersTask + } + + def compileJavaWithJavacTaskName = "compile${buildTypeName}JavaWithJavac" + def compileJavaWithJavacTask = tasks.findByName(compileJavaWithJavacTaskName) + + + if (compileJavaWithJavacTask) { + dependsOn compileJavaWithJavacTask + } + + def compileKotlinTaskName = "compile${buildTypeName}Kotlin" + def compileKotlinTask = tasks.findByName(compileKotlinTaskName) + + + if (compileKotlinTask) { + dependsOn compileKotlinTask + } + + + def mergeDexTaskName = "mergeDex${buildTypeName}" + def mergeDexTask = tasks.findByName(mergeDexTaskName) + + if (mergeDexTask) { + dependsOn mergeDexTask + } + + def checkDuplicateClassesTaskName = "check${buildTypeName}DuplicateClasses" + def checkDuplicateClassesTask = tasks.findByName(checkDuplicateClassesTaskName) + + if (checkDuplicateClassesTask) { + dependsOn checkDuplicateClassesTask + } + + def generateBuildConfigTaskName = "generate${buildTypeName}BuildConfig" + def generateBuildConfigTask = tasks.findByName(generateBuildConfigTaskName) + + if (generateBuildConfigTask) { + dependsOn generateBuildConfigTask + } + + def dexBuilderTaskName = "dexBuilder${buildTypeName}" + def dexBuilderTask = tasks.findByName(dexBuilderTaskName) + + if (dexBuilderTask) { + dependsOn dexBuilderTask + } + + + def mergeExtDexTaskName = "mergeExtDex${buildTypeName}" + def mergeExtDexTask = tasks.findByName(mergeExtDexTaskName) + + if (mergeExtDexTask) { + dependsOn mergeExtDexTask + } + + def mergeLibDexTaskName = "mergeLibDex${buildTypeName}" + def mergeLibDexTask = tasks.findByName(mergeLibDexTaskName) + + if (mergeLibDexTask) { + dependsOn mergeLibDexTask + } + + def mergeProjectDexTaskName = "mergeProjectDex${buildTypeName}" + def mergeProjectDexTask = tasks.findByName(mergeProjectDexTaskName) + + if (mergeProjectDexTask) { + dependsOn mergeProjectDexTask + } + + def syncLibJarsTaskName = "sync${buildTypeName}LibJars" + def syncLibJarsTask = tasks.findByName(syncLibJarsTaskName) + + if (syncLibJarsTask) { + dependsOn syncLibJarsTask + } + + def mergeJavaResourceTaskName = "merge${buildTypeName}JavaResource" + def mergeJavaResourceTask = tasks.findByName(mergeJavaResourceTaskName) + + if (mergeJavaResourceTask) { + dependsOn mergeJavaResourceTask + } + + def mergeJniLibFoldersTaskName = "merge${buildTypeName}JniLibFolders" + def mergeJniLibFoldersTask = tasks.findByName(mergeJniLibFoldersTaskName) + + if (mergeJniLibFoldersTask) { + dependsOn mergeJniLibFoldersTask + } + + def mergeNativeLibsTaskName = "merge${buildTypeName}NativeLibs" + def mergeNativeLibsTask = tasks.findByName(mergeNativeLibsTaskName) + + if (mergeNativeLibsTask) { + dependsOn mergeNativeLibsTask + } + + def stripDebugSymbolsTaskName = "strip${buildTypeName}DebugSymbols" + def stripDebugSymbolsTask = tasks.findByName(stripDebugSymbolsTaskName) + + if (stripDebugSymbolsTask) { + dependsOn stripDebugSymbolsTask + } + + def validateSigningTaskName = "validateSigning${buildTypeName}" + def validateSigningTask = tasks.findByName(validateSigningTaskName) + + if (validateSigningTask) { + dependsOn validateSigningTask + } + + + def extractProguardFilesTaskName = "extractProguardFiles" + def extractProguardFilesTask = tasks.findByName(extractProguardFilesTaskName) + + if (extractProguardFilesTask) { + dependsOn extractProguardFilesTask + } + + + def compileArtProfileTaskName = "compile${buildTypeName}ArtProfile" + def compileArtProfileTask = tasks.findByName(compileArtProfileTaskName) + + if (compileArtProfileTask) { + dependsOn compileArtProfileTask + } + + + def extractNativeSymbolTablesTaskName = "extract${buildTypeName}NativeSymbolTables" + def extractNativeSymbolTablesTask = tasks.findByName(extractNativeSymbolTablesTaskName) + + if (extractNativeSymbolTablesTask) { + dependsOn extractNativeSymbolTablesTask + } + + + def optimizeResourcesTaskName = "optimize${buildTypeName}Resources" + def optimizeResourcesTask = tasks.findByName(optimizeResourcesTaskName) + + if (optimizeResourcesTask) { + dependsOn optimizeResourcesTask + } + + def bundleResourcesTaskName = "bundle${buildTypeName}Resources" + def bundleResourcesTask = tasks.findByName(bundleResourcesTaskName) + + if (bundleResourcesTask) { + dependsOn bundleResourcesTask + } + + } + dependsOn copyMetadataFilters // As some external gradle plugins can reorder the execution order of the tasks it may happen that buildMetadata is executed after merge{Debug/Release}Assets @@ -754,20 +909,24 @@ task buildMetadata(type: BuildToolTask) { inputs.files("$MDG_JAVA_DEPENDENCIES") // make MDG aware of whitelist.mdg and blacklist.mdg files - inputs.files(project.fileTree(dir: "$rootDir", include: "**/*.mdg")) + // inputs.files(project.fileTree(dir: "$rootDir", include: "**/*.mdg")) + // use explicit inputs as the above makes the whole build-tools directory an input! + inputs.files("$BUILD_TOOLS_PATH/whitelist.mdg", "$BUILD_TOOLS_PATH/blacklist.mdg") - def classesDir = "$buildDir/intermediates/javac" - inputs.dir(classesDir) + def classesDir = layout.buildDirectory.dir("intermediates/javac").get().asFile + if (classesDir.exists()) { + inputs.dir(classesDir) + } - def kotlinClassesDir = "$buildDir/tmp/kotlin-classes" - if (file(kotlinClassesDir).exists()) { + def kotlinClassesDir = layout.buildDirectory.dir("tmp/kotlin-classes").get().asFile + if (kotlinClassesDir.exists()) { inputs.dir(kotlinClassesDir) } outputs.files("$METADATA_OUT_PATH/treeNodeStream.dat", "$METADATA_OUT_PATH/treeStringsStream.dat", "$METADATA_OUT_PATH/treeValueStream.dat") workingDir "$BUILD_TOOLS_PATH" - main "-jar" + mainClass = "-jar" doFirst { // get compiled classes to pass to metadata generator @@ -780,8 +939,8 @@ task buildMetadata(type: BuildToolTask) { rootProject.subprojects { - def projectClassesDir = new File("$it.buildDir/intermediates/javac") - def projectKotlinClassesDir = new File("$it.buildDir/tmp/kotlin-classes") + def projectClassesDir = it.layout.buildDirectory.dir("intermediates/javac").get().asFile + def projectKotlinClassesDir = it.layout.buildDirectory.dir("tmp/kotlin-classes").get().asFile if (projectClassesDir.exists()) { def projectClassesSubDirs = projectClassesDir.listFiles() @@ -792,14 +951,14 @@ task buildMetadata(type: BuildToolTask) { } } - if (projectKotlinClassesDir.exists()) { - def projectKotlinClassesSubDirs = projectKotlinClassesDir.listFiles(); - for (File subDir : projectKotlinClassesSubDirs) { - if (!kotlinClassesSubDirs.contains(subDir)) { - kotlinClassesSubDirs.add(subDir) - } + if (projectKotlinClassesDir.exists()) { + def projectKotlinClassesSubDirs = projectKotlinClassesDir.listFiles() + for (File subDir : projectKotlinClassesSubDirs) { + if (!kotlinClassesSubDirs.contains(subDir)) { + kotlinClassesSubDirs.add(subDir) + } + } } - } } def generatedClasses = new LinkedList() @@ -816,7 +975,7 @@ task buildMetadata(type: BuildToolTask) { } def store = new ArrayList() - for (String dir: generatedClasses){ + for (String dir : generatedClasses) { listf(dir, store) } @@ -839,13 +998,13 @@ task buildMetadata(type: BuildToolTask) { setOutputs outLogger def paramz = new ArrayList() - paramz.add("android-metadata-generator.jar") + paramz.add(Paths.get(rootPath, "android-metadata-generator.jar")) - if(enableAnalytics){ + if (enableAnalytics) { paramz.add("analyticsFilePath=$analyticsFilePath") } - if(enableVerboseMDG){ + if (enableVerboseMDG) { paramz.add("verbose") } @@ -862,7 +1021,7 @@ task generateTypescriptDefinitions(type: BuildToolTask) { def includeDirs = ["com.android.support", "/platforms/" + android.compileSdkVersion] workingDir "$BUILD_TOOLS_PATH" - main "-jar" + mainClass = "-jar" doFirst { delete "$TYPINGS_PATH" @@ -907,7 +1066,7 @@ static def shouldIncludeDirForTypings(path, includeDirs) { return false } -task copyTypings { +task 'copyTypings' { doLast { outLogger.withStyle(Style.Info).println "Copied generated typings to application root level. Make sure to import android.d.ts in reference.d.ts" @@ -921,12 +1080,12 @@ task copyTypings { copyTypings.onlyIf { generateTypescriptDefinitions.didWork } generateTypescriptDefinitions.finalizedBy(copyTypings) -task validateAppIdMatch { +task 'validateAppIdMatch' { doLast { def lineSeparator = System.getProperty("line.separator") if (project.hasProperty("nsApplicationIdentifier") && !project.hasProperty("release")) { - if (project.nsApplicationIdentifier != android.defaultConfig.applicationId) { + if (project.nsApplicationIdentifier != android.defaultConfig.applicationId && android.namespace != appIdentifier) { def errorMessage = "${lineSeparator}WARNING: The Application identifier is different from the one inside \"package.json\" file.$lineSeparator" + "NativeScript CLI might not work properly.$lineSeparator" + "Remove applicationId from app.gradle and update the \"nativescript.id\" in package.json.$lineSeparator" + @@ -965,3 +1124,186 @@ task cleanMdg(type: Delete) { cleanSbg.dependsOn(cleanMdg) clean.dependsOn(cleanSbg) + + +//dependsOn { +// pattern { +// include "merge*.Shaders" // Matches tasks starting with "merge" and ending with "Shaders" +// } +//} + + +tasks.configureEach({ DefaultTask currentTask -> + // println "\t ~ [DEBUG][app] build.gradle - currentTask = ${currentTask.name} ..." + + if (currentTask =~ /compile.+JavaWithJavac/) { + currentTask.dependsOn(runSbg) + } + + if (currentTask =~ /mergeDex.+/) { + currentTask.dependsOn(runSbg) + } + + if (currentTask =~ /compile.+Kotlin.+/) { + currentTask.dependsOn(runSbg) + } + + if (currentTask =~ /merge.*Assets/) { + currentTask.dependsOn(buildMetadata) + } + +// // ensure buildMetadata is done before R8 to allow custom proguard from metadata + if (currentTask =~ /minify.*WithR8/) { + buildMetadata.finalizedBy(currentTask) + } + if (currentTask =~ /assemble.*Debug/ || currentTask =~ /assemble.*Release/) { + currentTask.finalizedBy("validateAppIdMatch") + } + + if (currentTask =~ /process.+Resources/) { + cleanupAllJars.dependsOn(currentTask) + } + +// if (currentTask.name == "extractProguardFiles") { +// currentTask.finalizedBy(buildMetadata) +// } +// + if (currentTask =~ /generate.+LintVitalReportModel/) { + currentTask.dependsOn(buildMetadata) + } + + if (currentTask =~ /lintVitalAnalyze.+/) { + currentTask.dependsOn(buildMetadata) + } +// +// if (currentTask =~ /merge.+GlobalSynthetics/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /optimize.+Resources/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /buildCMake.*/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /configureCMake.*/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /validateSigning.*/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /generate.*LintReportModel/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /generate.*AndroidTestResValues/) { +// // buildMetadata.dependsOn(currentTask) +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /generate.*AndroidTestLintModel/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /generate.*UnitTestLintModel/) { +// buildMetadata.mustRunAfter(currentTask) +// } +// +// if (currentTask =~ /generate.*UnitTestLintModel/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// +// if (currentTask =~ /lintAnalyze.*UnitTest/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /process.*JavaRes/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /strip.*DebugSymbols/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /merge.*JavaResource/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /lintAnalyze.*/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /lintAnalyze.*AndroidTest/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /bundle.*Resources/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /compile.*ArtProfile/) { +// currentTask.mustRunAfter(buildMetadata) +// } +// +// if (currentTask =~ /check.*DuplicateClasses/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /check.*AarMetadata/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /create.*CompatibleScreenManifests/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /process.*Manifest/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /generate.*ResValues/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /merge.*Resources/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /package.*Resources/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /process.*Resources/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /desugar.*Dependencies/) { +// currentTask.finalizedBy(buildMetadata) +// } +// +// if (currentTask =~ /merge.*JniLibFolders/) { +// currentTask.finalizedBy(buildMetadata) +// } + +}) + +rootProject.subprojects.forEach { + it.tasks.configureEach({ DefaultTask currentTask -> + if (currentTask =~ /.+bundleLibCompileToJar.*/) { + currentTask.finalizedBy(cleanupAllJars) + } + + if (currentTask =~ /bundleLibRuntimeToDir.*/) { + currentTask.finalizedBy(buildMetadata) + } + + if (currentTask =~ /compile.*LibraryResources/) { + currentTask.finalizedBy(buildMetadata) + } + }) +} diff --git a/test-app/app/src/debug/java/com/tns/ErrorReport.java b/test-app/app/src/debug/java/com/tns/ErrorReport.java index 83e7f3751..d2b5cf2d6 100644 --- a/test-app/app/src/debug/java/com/tns/ErrorReport.java +++ b/test-app/app/src/debug/java/com/tns/ErrorReport.java @@ -19,13 +19,17 @@ import android.app.PendingIntent.CanceledException; import android.content.ClipData; import android.content.ClipboardManager; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.os.Environment; import com.google.android.material.tabs.TabLayout; + +import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -33,7 +37,15 @@ import androidx.viewpager.widget.ViewPager; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; + +import android.text.SpannableString; +import android.text.SpannableStringBuilder; +import android.text.method.LinkMovementMethod; import android.text.method.ScrollingMovementMethod; +import android.text.style.AbsoluteSizeSpan; +import android.text.style.ClickableSpan; +import android.text.style.ForegroundColorSpan; +import android.text.style.StyleSpan; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -42,7 +54,6 @@ import android.widget.TextView; import android.widget.Toast; - class ErrorReport implements TabLayout.OnTabSelectedListener { public static final String ERROR_FILE_NAME = "hasError"; private static AppCompatActivity activity; @@ -349,26 +360,96 @@ public int getCount() { } } - public static class ExceptionTab extends Fragment { + + public static class ExceptionTab extends Fragment { + + public SpannableStringBuilder getStyledStacktrace(String trace) { + if (trace == null) return null; + String[] traceLines = trace.trim().split("\n"); + SpannableStringBuilder builder = new SpannableStringBuilder(); + boolean firstLine = true; + for (String line: traceLines) { + if (firstLine) { + firstLine = false; + } else { + builder.append("\n"); + builder.append("\n"); + } + + String[] nameAndPath = line.trim().split("\\("); + SpannableString nameSpan = new SpannableString(nameAndPath[0]); + nameSpan.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, nameAndPath[0].length(), 0); + builder.append(nameSpan); + + builder.append(" "); + if (nameAndPath.length > 1) { + SpannableString pathSpan = new SpannableString("(" + nameAndPath[1]); + pathSpan.setSpan(new AbsoluteSizeSpan(13, true),0, nameAndPath[1].length() + 1, 0); + pathSpan.setSpan(new ClickableSpan() { + @Override + public void onClick(@NonNull View widget) { + Log.d("JS", line.trim()); + } + }, 0,nameAndPath[1].length() + 1, 0); + pathSpan.setSpan(new ForegroundColorSpan(Color.GRAY),0, nameAndPath[1].length() + 1, 0); + + builder.append(pathSpan); + } + } + return builder; + } + + public static void restartApp(Context context) { + PackageManager packageManager = context.getPackageManager(); + Intent intent = packageManager.getLaunchIntentForPackage(context.getPackageName()); + ComponentName componentName = intent.getComponent(); + Intent mainIntent = Intent.makeRestartActivityTask(componentName); + context.startActivity(mainIntent); + java.lang.Runtime.getRuntime().exit(0); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int exceptionTabId = container.getContext().getResources().getIdentifier("exception_tab", "layout", container.getContext().getPackageName()); View view = inflater.inflate(exceptionTabId, container, false); - int txtViewId = container.getContext().getResources().getIdentifier("txtErrorMsg", "id", container.getContext().getPackageName()); - TextView txtErrorMsg = (TextView) view.findViewById(txtViewId); - txtErrorMsg.setText(exceptionMsg); - txtErrorMsg.setMovementMethod(new ScrollingMovementMethod()); + int errorExceptionViewId = activity.getResources().getIdentifier("errorException", "id", activity.getPackageName()); + TextView errorExceptionView = (TextView) activity.findViewById(errorExceptionViewId); + errorExceptionView.setMovementMethod(new ScrollingMovementMethod()); + + int errorStackTraceViewId = container.getContext().getResources().getIdentifier("errorStacktrace", "id", container.getContext().getPackageName()); + TextView errorStackTraceView = (TextView) view.findViewById(errorStackTraceViewId); + + String[] exceptionParts = exceptionMsg.split("StackTrace:"); + String error = exceptionParts[0]; + String trace = ""; + + if (exceptionParts.length > 1) { + for (int i=0;i < exceptionParts.length;i++) { + if (i == 0) continue; + trace += exceptionParts[i]; + } + } + + errorExceptionView.setText(error.trim()); + + errorStackTraceView.setText(trace != null ? getStyledStacktrace(trace) : "", TextView.BufferType.SPANNABLE); + errorStackTraceView.setMovementMethod(new ScrollingMovementMethod()); + errorStackTraceView.setMovementMethod(LinkMovementMethod.getInstance()); + errorStackTraceView.setEnabled(true); int btnCopyExceptionId = container.getContext().getResources().getIdentifier("btnCopyException", "id", container.getContext().getPackageName()); Button copyToClipboard = (Button) view.findViewById(btnCopyExceptionId); - copyToClipboard.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("nsError", exceptionMsg); - clipboard.setPrimaryClip(clip); - } + + int btnRestartAppId = container.getContext().getResources().getIdentifier("btnRestartApp", "id", container.getContext().getPackageName()); + Button restartApp = (Button) view.findViewById(btnRestartAppId); + restartApp.setOnClickListener(v -> { + restartApp(getContext().getApplicationContext()); + }); + copyToClipboard.setOnClickListener(v -> { + ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("nsError", exceptionMsg); + clipboard.setPrimaryClip(clip); }); return view; diff --git a/test-app/app/src/debug/res/drawable/button.xml b/test-app/app/src/debug/res/drawable/button.xml new file mode 100644 index 000000000..ec005653c --- /dev/null +++ b/test-app/app/src/debug/res/drawable/button.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/test-app/app/src/debug/res/drawable/button_accented.xml b/test-app/app/src/debug/res/drawable/button_accented.xml new file mode 100644 index 000000000..2d5065498 --- /dev/null +++ b/test-app/app/src/debug/res/drawable/button_accented.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/test-app/app/src/debug/res/layout/error_activity.xml b/test-app/app/src/debug/res/layout/error_activity.xml index d00b3695a..9e614f6f3 100644 --- a/test-app/app/src/debug/res/layout/error_activity.xml +++ b/test-app/app/src/debug/res/layout/error_activity.xml @@ -1,39 +1,62 @@ - - + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:background="@color/gray" + tools:context="com.tns.ErrorReportActivity" + android:theme="@style/Widget.AppCompat.Light.ActionBar"> - - - - - \ No newline at end of file + android:textColor="@color/white" + android:paddingVertical="10dp" + android:paddingRight="16dp" /> + + + + + + + + + + + + + diff --git a/test-app/app/src/debug/res/layout/exception_tab.xml b/test-app/app/src/debug/res/layout/exception_tab.xml index 4e9bca2bb..4d3a545f4 100644 --- a/test-app/app/src/debug/res/layout/exception_tab.xml +++ b/test-app/app/src/debug/res/layout/exception_tab.xml @@ -1,52 +1,71 @@ - -