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.
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>
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:
Try navigating to (android/app/build/intermediates/res/merged/release/
See if there's any drawable-* folder
Perform rm -rf android/app/build/intermediates/res/merged/release/drawable-*)
Try again ./gradlew assembleRelease (you probably still fail to build here)
Back to the same folder, remove .DS_Store
Build again
Hopefully succeed
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
I FINALLY CAN CREATE RELEASE APK
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
Open file named build.gradle and look for section name signingConfigs
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'
}
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
Save the file with any name and set the extension to .BAT
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
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.
Related
I've been setting up Azure App Center build pipelines and after some troubleshooting, I managed to make our debug build succeed. The issue is that, it seems to not be able to find any of the generated APKs in the expected directories. Any ideas on why that is?
Here's the specific part of the output log:
BUILD SUCCESSFUL in 4m 28s 130 actionable tasks: 124 executed, 6
up-to-date
##[section]Finishing: Gradle Task
##[section]Starting: Android Postprocess
============================================================================== Task : Shell script Description : Run a shell script using
Bash Version : 2.206.0 Author : Microsoft Corporation Help
:
https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/shell-script
============================================================================== [command]/bin/bash
/Users/runner/runners/2.206.1/scripts/android-postprocess.sh
/Users/runner/work/1/s/build/outputs/apk Removing all ABI or density
dependent APKsā¦ find: /Users/runner/work/1/s/build/outputs/apk: No
such file or directory find: /Users/runner/work/1/s/build/outputs/apk:
No such file or directory find:
/Users/runner/work/1/s/build/outputs/apk: No such file or directory
Found 0 APK file(s) Found 0 unaligned APK file(s) find:
/Users/runner/work/1/s/build/outputs/apk: No such file or directory
/Users/runner/runners/2.206.1/scripts/android-postprocess.sh: line 36:
pushd: /Users/runner/work/1/s/build/outputs/apk/..: No such file or
directory
/Users/runner/runners/2.206.1/scripts/android-postprocess.sh: line 43:
popd: directory stack empty
##[error]The process '/bin/bash' failed with exit code 1
##[error]Bash failed with error: The process '/bin/bash' failed with exit code 1
##[section]Finishing: Android Postprocess
I also have a post-clone bash script for generating the local.properties file which contains some secrets, and it seems to work just fine since the build uses it and goes through with it.
Sadly, I can't infer much from the logs, I'm not a DevOps engineer and have practically 0 experience in this sector.
I am trying to load a schema through introspection: according to the docs I should run the following in my project root directory:
mkdir -p app/src/main/graphql/com/example/rocketreserver/ ./gradlew :app:downloadApolloSchema -Pcom.apollographql.apollo.endpoint='https://apollo-fullstack-tutorial.herokuapp.com/' -Pcom.apollographql.apollo.schema='src/main/graphql/com/example/rocketreserver/schema.json'
So, I changed it to:
mkdir -p app/src/main/graphql/com/myapp/ ./gradlew :app:downloadApolloSchema -Pcom.apollographql.apollo.endpoint='http://localhost:4000/graphql/' -Pcom.apollographql.apollo.schema='src/main/graphql/com/myapp/schema.json'
However I'm getting the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Project '.apollographql.apollo.endpoint=http' not found in root project 'MyApp'.
I've added the apollo plugin in the app level gradle file:
id("com.apollographql.apollo").version("2.3.1")
I've also registered the task like:
tasks.register("downloadSchema", com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask.class) {
endpointUrl.set("https://localhost:4000/graphql")
schemaFilePath.set("src/main/graphql/com/myapp/schema.json")
}
I'm not sure what the error means exactly, I've searched for it, but can't find a reference or a solution.
Note: I get the same error when I try to run the exact same command given in the docs.
Turns out the command posted in the docs is wrong, it should be:
mkdir -p app/src/main/graphql/com/bangenergy/ ./gradlew :app:downloadApolloSchema -P com.apollographql.apollo.endpoint='http://localhost:4000/graphql/' -P com.apollographql.apollo.schema='src/main/graphql/com/bangenergy/schema.json'
Notice the space between -P and com.
This is the Windows Command
gradlew :app:downloadApolloSchema --endpoint="http://****REPLACE_WITH_YOUR_ENDPOINT/graphql/" --schema="src/main/graphql/com/example/programbuilder/schema.json"
Also the com.apollographql.apollo.schema deprecated with --schema and com.apollographql.apollo.endpoint deprecated with --endpoint
The error on the above title only occurs on this specific project, when I build a Blank project it doesn't get this error. I've tried the other solutions to this problem but I just can't seem to get this working.
Heres the error message:
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
ANDROID_HOME=C:\Users\ME\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_211
Running command: cmd "/s /c ""C:\Program Files (x86)\gradle-5.6.2\bin\gradle.bat" -p C:\Windows\System32\QRID2\qrid\platforms\android wrapper -b C:\Windows\System32\QRID2\qrid\platforms\android\wrapper.gradle""
Command finished with error code ENOENT: cmd /s /c ""C:\Program Files (x86)\gradle-5.6.2\bin\gradle.bat" -p C:\Windows\System32\QRID2\qrid\platforms\android wrapper -b C:\Windows\System32\QRID2\qrid\platforms\android\wrapper.gradle"
cmd: Command failed with exit code ENOENT
Error: cmd: Command failed with exit code ENOENT
at ChildProcess.whenDone (C:\Windows\System32\QRID2\qrid\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
at ChildProcess.emit (events.js:198:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
This means ENOENT Error NO ENTity|ENTry so such derectory
check your gradle is located in C:\Program Files (x86)\gradle-5.6.2
Do you have the gradle installed on your machine?
Try it:
1 - download the gradle from the site gradle.org.
Download the .zip file and extract to disk C:\
2 - Set the Gradle Environment Variables.
In order for the Gradle executable to be visible on the Windows command line, you must set the GRADLE_HOME variable and expose it in the system path.
Example:
variable name: GRADLE_HOME
variable value: c:\gradle-2.5
and then add GRADLE_HOME to Path
;%GRADLE_HOME%\bin
Restart your PC and use de command line
gradle -version
To see if it works
I'm testing gitlab ci/cd and I'm trying to build a signed APK but my
script failed. What should I change or add?
I add variables KEYSTORE_FILE, KEYSTORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD
with values.
assembleRelease:
stage: release
script:
- echo $KEYSTORE_FILE | base64 -d > my.keystore
- ./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/my.keystore
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD
-Pandroid.injected.signing.key.alias=$KEY_ALIAS
-Pandroid.injected.signing.key.password=$KEY_PASSWORD
artifacts:
paths:
- app/build/outputs/apk/release
Error:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:packageRelease'.
1 exception was raised by workers:
java.lang.RuntimeException:
com.android.ide.common.signing.KeytoolException: Failed to read key from
store "/builds/juantamad.02072019/2019_samplebuild/my.keystore": null
But it should be successfully
Provided you have correct indentations (as posted they are not), the problem is likely to be caused by multi-line command - it just executes - ./gradlew assembleRelease first, without further arguments
To wrap the long line you can use YAML multi-line strings:
script:
- ...
- >
./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/my.keystore
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD
-Pandroid.injected.signing.key.alias=$KEY_ALIAS
-Pandroid.injected.signing.key.password=$KEY_PASSWORD
Read more:
In YAML, how do I break a string over multiple lines?
https://gitlab.com/snippets/1717579
--
Another possible cause - if your env var is set as Protected in project settings,
and you are working in a branch which is not Protected.
Then var is not passed to your job
I tried to run rake run:android the follwing occurs, kindly assist me.
AndroidManifest change file [C:/Users/giridhran/workspace/myfirst/bin/libs/relea
se/arm-linux-androideabi/4.4.3/extensions/AndroidManifest.xml] from native exten
sion not found !
delete original manifest
Manifest updated by extension saved!
EXT: add additional files to project before build
PWD: C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rhodes-3.3.2
CMD: D:/installer/android-sdk_r11-windows/android-sdk-windows/platform-tools/aap
t.exe package -f -M C:/Users/giridhran/workspace/myfirst/bin/tmp/AndroidManifest
.xml -S C:/Users/giridhran/workspace/myfirst/bin/tmp/res -A C:/RhoStudio/ruby/li
b/ruby/gems/1.8/gems/rhodes-3.3.2/platform/android/Rhodes/assets -I D:/installer
/android-sdk_r11-windows/android-sdk-windows/platforms/android-8/android.jar -J
C:/Users/giridhran/workspace/myfirst/bin/tmp
C:\Users\giridhran\workspace\myfirst\bin\tmp\AndroidManifest.xml:30: error: No r
esource identifier found for attribute 'xlargeScreens' in package 'android'
Error in AAPT
Before running rake run:android command, please ensure that:
you have set the path of java-bin folder.
you have set the path of Android SDK & NDK.
check the android version in build.xml file.