2

I have tried to assemble my project as a release. But it always failed. Below are some of the script that I use to build my apk as release:-

BUILD SUCCESSFUL

.\gradlew assembleDebug --no-daemon
.\gradlew app:assembleDebug

BUILD FAILED

.\gradlew app:assembleRelease
.\gradlew assembleRelease -x bundleReleaseJsAndAssets

The result of the failed mention on every failed build:-

> Execution failed for task ':app:mergeReleaseResources'
> Task :app:mergeReleaseResources
> FAILED cvc-type.3.1.3: The value '' of element 'id' is not valid.

enter image description here

enter image description here

enter image description here

I also have try to create keystore using keytool and apply it to the signingConfigs in

./android/app/build.gradle

but no success on release. So, I'm reverting and use default debug.keystore value

Referring various answer from forum, SO question, tutorial I have try to apply. I'm totally stuck.

Does anyone face this issue and able to overcome the obstacles?

Edited: Error log when build

Using .\gradlew assembleRelease

D:\Project\Clients\android>.\gradlew assembleRelease

> Configure project :react-native-activity-result
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.

> Task :react-native-activity-result:verifyReleaseResources FAILED

> Task :app:bundleReleaseJsAndAssets
Loading dependency graph, done.
info Writing bundle output to:, D:\Project\Clients\android\app\build\generated\assets\react\release\index.android.bundle
info Writing sourcemap output to:, D:\Project\Clients\android\app\build\intermediates\sourcemaps\release\index.android.bundle.packager.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 47 asset files
info Done copying assets

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-activity-result:verifyReleaseResources'.
> 1 exception was raised by workers:
  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
  error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v26\values-v26.xml:7: error: resource android:attr/colorError not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v26\values-v26.xml:11: error: resource android:attr/colorError not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v26\values-v26.xml:15: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2734: error: resource android:attr/fontStyle not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2735: error: resource android:attr/font not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2736: error: resource android:attr/fontWeight not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2737: error: resource android:attr/fontVariationSettings not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2738: error: resource android:attr/ttcIndex not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2902: error: resource android:attr/startX not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2905: error: resource android:attr/startY not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2908: error: resource android:attr/endX not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2911: error: resource android:attr/endY not found.
  D:\Project\Clients\node_modules\react-native-activity-result\android\build\intermediates\res\merged\release\values\values.xml:2919: error: resource android:attr/offset not found.
  error: failed linking references.



* 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 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2m 54s
210 actionable tasks: 22 executed, 188 up-to-date

D:\Project\Clients\android> 
Luiey
  • 843
  • 2
  • 23
  • 50

3 Answers3

0

Used to face this, it was an APPT2 issue (at least in my case). From the screenshot shared, it tells you Duplicate resources. This may happen after you performed a js bundling, and few folders with resources were created.

Below's how I take care APPT2 issue:

  1. Try navigating to (android/app/build/intermediates/res/merged/release/
  2. See if there's any drawable-* folder
  3. Perform rm -rf android/app/build/intermediates/res/merged/release/drawable-*)
  4. Try again ./gradlew assembleRelease (you probably still fail to build here)
  5. Back to the same folder, remove .DS_Store
  6. Build again
  7. Hopefully succeed
Tommy Leong
  • 2,509
  • 6
  • 30
  • 54
  • I have try your approach, still same result. 1. Folder drawable not exist in release folder 2. .\gradlew assembleRelease failed but no .DS_Store in my folder (already enable to show Hidden items) – Luiey Nov 07 '19 at 04:36
  • Can you share the full error message? The screenshot provided has cut of half of the message. Maybe just do an edit to your question. – Tommy Leong Nov 07 '19 at 06:10
  • I have edit for error log. Different command will result in different output error. I have try:- `.\gradlew assembleRelease`, `.\gradlew app:assembleRelease` and `gradlew assembleRelease -x bundleReleaseJsAndAssets`. All 3 command will output different error and the error too long to be place inside my question – Luiey Nov 07 '19 at 06:37
  • According to [this solution here](https://stackoverflow.com/questions/49331411/errorresource-androidstyle-textappearance-material-widget-button-borderless-co), it seems to be your project is using a lower SDK version (23). Trying changing your compileSdkVersion to 28 might help. – Tommy Leong Nov 07 '19 at 06:49
  • I have try before changing the target SDK and the compile/implementation warning. But still unsuccessful build `> Task :app:mergeReleaseResources FAILED`. If I .\gradlew clean and build back, the version will be revert to original again. – Luiey Nov 07 '19 at 07:12
  • `./gradlew clean` can't possibly resetting your version back to original, what it does is the remove the build in your android directory. I suggest you to try again in clean state and upgrade your compileSdkVersion and rebuild. – Tommy Leong Nov 07 '19 at 07:26
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/201985/discussion-between-tommyleong-and-luiey). – Tommy Leong Nov 07 '19 at 07:33
0

In some react native version it is a bug. you can do the following:

in the node_modules/react-native folder, find the react.gradle file,

then after the doFirst add the following code:

 doLast {
    def moveFunc = { resSuffix ->
        File originalDir = 
    file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
        if (originalDir.exists()) {
            File destDir = 
    file("$buildDir/../src/main/res/drawable-${resSuffix}");
            ant.move(file: originalDir, tofile: destDir);
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

then you can use the ./gradlew assembleRelease generate the apk.
At the same time, when you want to know what the errr is during the build process, you can use ./gradlew assembleRelease --info commod

Lenoarod
  • 3,441
  • 14
  • 25
  • I have try this yesterday based from my error and it is also not successful build release. – Luiey Nov 07 '19 at 05:31
0

I FINALLY CAN CREATE RELEASE APK

  1. Create a keystore by running command keytool -genkey -v -keystore myappkeystore.keystore -alias myappalias-keyalg RSA -keysize 2048 -validity 10000 and place it on .\android\app. Details instruction can be follow from here
  2. Open file named build.gradle and look for section name signingConfigs
  3. Insert below script after debug keyname and replace with what key that you register:-

    release {
        storeFile file('mycreatedkeystore.keystore')
        storePassword 'mypassword'
        keyAlias 'mykeyalias'
        keyPassword 'mypassword'
    }
    
  4. Open blank notepad and paste below script:-

    @echo off
    :: BatchGotAdmin
    :-------------------------------------
    REM  --> Check for permissions
    >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
    
    REM --> If error flag set, we do not have admin.
    if '%errorlevel%' NEQ '0' (
        echo Requesting administrative privileges...
        goto UACPrompt
    ) else ( goto gotAdmin )
    
    :UACPrompt
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
        set params = %*:"=""
        echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    
        "%temp%\getadmin.vbs"
        del "%temp%\getadmin.vbs"
        exit /B
    
    :gotAdmin
        pushd "%CD%"
        CD /D "%~dp0"
    :--------------------------------------
    if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
    set driveName="%CD:~0,2%"
    set currentFolder="%~dp0"
    setlocal enableextensions enabledelayedexpansion
    set /A count=1
    set list=
    CD %driveName%
    
    echo ===========================================
    for /d %%D in (*) do (
        set "listName=%%~f"
        set list=%listName%%1
        rem echo !listName! !
        echo !count!^. %%~D
        set /a count+=1
    )
    echo ===========================================
    :startAgain
    set choice=
    set /p choice=Type in target folder from listing to build release APK (e.g. targetfolder): 
    if not '%choice%'=='' (
        if exist %choice% (
            set choice=%choice%
            CD %choice%
            goto performbuild
        )
    )
    echo Invalid directory name!
    goto startAgain
    
    :performbuild
    echo Script will start build target APK to release on %choice%...
    timeout /t 2 /nobreak>nul
    call react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
    rem start "" %currentFolder%%choice%^\android\app\src\main\res
    timeout /t 2 /nobreak>nul
    cd %currentFolder%%choice%^\android\app\src\main\res
    echo Validating duplicating resources
    if exist "drawable-hdpi" rmdir "drawable-hdpi" /q /s
    if exist "drawable-mdpi" rmdir "drawable-mdpi" /q /s
    if exist "drawable-xhdpi" rmdir "drawable-xhdpi" /q /s
    if exist "drawable-xxhdpi" rmdir "drawable-xxhdpi" /q /s
    if exist "drawable-xxxhdpi" rmdir "drawable-xxxhdpi" /q /s
    if exist "raw" rmdir "raw" /q /s
    cd %currentFolder%%choice%^\android
    call gradlew assembleRelease -x bundleReleaseJsAndAssets
    start "" %currentFolder%%choice%^\android\app\build\outputs\apk\release"
    cd %currentFolder%%choice%
    :choiceOpt
    set /P answ=Build complete. Do you want to rebuild again[Y/N]?
    if /I "%answ%" EQU "Y" goto :performbuild
    if /I "%answ%" EQU "N" goto :justexit
    goto :choiceOpt
    
    :justexit
    echo Exiting
    timeout /t 2 /nobreak>nul
    exit
    
  5. Save the file with any name and set the extension to .BAT

  6. Place the BAT file on one folder up of your root project e.g.

    • Your project folder:- C:\Project\Mobile\MyCurrentProject

    • Your batch file folder:- C:\Project\Mobile\releaseTool.bat

  7. Run the releaseTool.bat and the batch file with build the release version

I search and found several script to accomplish certain oart and combine it to make this batch script for RELEASE APK version

Disclaimer: I'm not an expert to elaborate the process or argue regarding the way I'm doing it (if it is not practical) because I have failed to build what I wanted and pieces-by-pieces solution is combined and become what I provided.

Luiey
  • 843
  • 2
  • 23
  • 50