generate release apk in react native - react-native

I create an simple application by react native. After finishing deploying now i want to make release apk so in order to according it's official site i have created key:
"C:\Program Files\Java\jdk1.8.0_162\bin\keytool.exe" -genkeypair -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
And i added :
MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=mypass
MYAPP_UPLOAD_KEY_PASSWORD=mypass
into the android/gradle.properties file and finally i added release part into signingConfigs section in android/app/build.gradle file:
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
and i added this sign config to buildTypes part:
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
but after running \android> ./gradlew bundleRelease :
PS F:\SafaProject\ReactNative\RNAuditMngm\android> ./gradlew bundleRelease
> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Loading dependency graph, done.
info Writing bundle output to:, F:\SafaProject\ReactNative\RNAuditMngm\android\app\build\generated\assets\react\release\index.android.bundle
info Writing sourcemap output to:, F:\SafaProject\ReactNative\RNAuditMngm\android\app\build\generated\sourcemaps\react\release\index.android.bundle.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 13 asset files
info Done copying assets
> Task :react-native-gesture-handler:compileReleaseJavaWithJavac
Note: F:\SafaProject\ReactNative\RNAuditMngm\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :react-native-reanimated:compileReleaseJavaWithJavac
Note: F:\SafaProject\ReactNative\RNAuditMngm\node_modules\react-native-reanimated\android\src\main\java\com\swmansion\reanimated\NodesManager.java uses or overrides a deprecated
API.
Note: Recompile with -Xlint:deprecation for details.
Note: F:\SafaProject\ReactNative\RNAuditMngm\node_modules\react-native-reanimated\android\src\main\java\com\swmansion\reanimated\NodesManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
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.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1m 54s
88 actionable tasks: 84 executed, 4 up-to-date
PS F:\SafaProject\ReactNative\RNAuditMngm\android>
It just create app.aab file in \app\build\outputs\bundle\release folder?
How could i create apk file?
This is complete app build.gradle

If you want to create .apk then run command :
cd android
./gradlew assembleRelease
It will generate release apk here :
android/app/build/output/apk/release/app-release.apk
If you want to generate a buldle (.aab) to upload to play store:
cd android
./gradlew bundleRelease

This is the way I generate a signed APK.
I'll also show you how to securely load in your gradle variables so that the project can be safely pushed to Git without exposing your passwords (something that is annoyingly not covered in tutorials).
1. Generate an upload key.
You can generate a private signing key using keytool. On Windows keytool must be run from C:\Program Files\Java\jdkx.x.x_x\bin.
keytool -genkeypair -v -storetype PKCS12 -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
This command prompts you for passwords for the keystore and key and for the Distinguished Name fields for your key. It then generates the keystore as a file called my-upload-key.keystore.
The keystore contains a single key, valid for 10000 days.
2. Setting up Gradle variables and safely loading them in
Place the my-upload-key.keystore file under the android/app directory in your project folder.
Create a new file in the android folder: android/keystore.properties and add the following (but obviously with your own passwords).
MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=YOUR_PASSWORD_HERE
MYAPP_UPLOAD_KEY_PASSWORD=YOUR_PASSWORD_HERE
Then add this new file to .gitignore so you can safely push to github without exposing your variables:
keystore.properties
Next, modify your android/app/build.gradle code to load in your keystore properties:
// Load keystore
def keystorePropertiesFile = rootProject.file("keystore.properties");
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
// ...
android{
// ...
signingConfigs {
release {
if ( keystorePropertiesFile.exists() ) {
storeFile file(keystoreProperties['MYAPP_UPLOAD_STORE_FILE'])
storePassword keystoreProperties['MYAPP_UPLOAD_STORE_PASSWORD']
keyAlias keystoreProperties['MYAPP_UPLOAD_KEY_ALIAS']
keyPassword keystoreProperties['MYAPP_UPLOAD_KEY_PASSWORD']
}
}
}
buildTypes {
release {
// ...
signingConfig signingConfigs.release
}
}
// ...
}
Doing it this way ensures that the project will still work if someone else clones it from Git without the keystore.properties file - perfect.
3. Generate the Android release bundle file manually
Remove current index.android.bundle file:
rm android/app/src/main/assets/index.android.bundle
If no such file exists then you will get ‘No such file or directory’ message.
Next, generate the android bundle, note the below is one command:
npx 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
You will likely get a “duplicate resources” error (at least I always do). Go to /android/app/src/main/res folder and delete any files that begin with “drawable”.
4. Generate the Android signed release build APK
Navigate to android folder:
cd android
And run the following command to generate your release APK:
./gradlew clean && ./gradlew assembleRelease
If any errors, delete android/.gradle and android/app/build/ and retry.
Your signed APK should now be located at android/app/build/outputs/apk/app-release.apk.
Once your build is successful then from your project’s root folder run below command to test your app in your device:
npx react-native run-android --variant=release
If you have any issues, try the following before re-doing the steps above:
Make sure to uninstall the old app on emulator/phone.
Delete old android/.gradle and android/app/build folder.
Npm cache clean –force.
Delete and reinstall node_modules.
I wrote this answer as an article for my own future reference but feel free to bookmark it :)

Related

conan doesn't upload export/conanfile.py to remote

I have created customized OpenCV package using conan package manager and uploaded it to a remote storage.
Workflow:
create package
cd c:\path\to\conanfile.py
conan create . smart/4.26 --profile ue4
Export with conan export . opencv-ue4/3.4.0#smart/4.26
Result:
c:\path\> conan export . opencv-ue4/3.4.0#smart/4.26
[HOOK - attribute_checker.py] pre_export(): WARN: Conanfile doesn't have 'url'. It is recommended to add it as attribute
Exporting package recipe
opencv-ue4/3.4.0#smart/4.26 exports_sources: Copied 3 '.patch' files: cmakes.patch, check_function.patch, typedefs.patch
opencv-ue4/3.4.0#smart/4.26: The stored package has not changed
opencv-ue4/3.4.0#smart/4.26: Exported revision: ceee251590f4bf50c4ff48f6dc27c2ed
I upload everything to the remote:
c:\path> conan upload -r bart opencv-ue4/3.4.0#rs7-smart/4.26 --all
Uploading to remote 'bart':
Uploading opencv-ue4/3.4.0#smart/4.26 to remote 'bart'
Recipe is up to date, upload skipped
Uploading package 1/1: 1d79899922d252aec6da136ce61bff640124c1c4 to 'bart'
Uploaded conan_package.tgz -> opencv-ue4/3.4.0#smart/4.26:1d79 [23667.97k]
Uploaded conaninfo.txt -> opencv-ue4/3.4.0#smart/4.26:1d79 [0.75k]
Uploaded conanmanifest.txt -> opencv-ue4/3.4.0#smart/4.26:1d79 [11.81k]
Our remote storage runs on the Artifactory, and I can see in a browser that conanfile.py is not listed anywhere.
I can also verify that directory C:\Users\user\.conan\data\opencv-ue4\3.4.0\smart\4.26\export on my Windows PC does contain both conanfile.py and conanmanifest.txt
I am using Windows PC for doing all above.
Now I'm trying to consume that package on another machine, running Ubuntu Linux.
Here is my conanfile.txt
[requires]
opencv-ue4/3.4.0#smart/4.26
[generators]
json
Command and results
> conan install -g json . opencv-ue4/3.4.0#smart/4.26
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=9
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
opencv-ue4/3.4.0#smart/4.26: Not found in local cache, looking in remotes...
opencv-ue4/3.4.0#smart/4.26: Trying with 'bart'...
Downloading conanmanifest.txt completed [0.33k]
opencv-ue4/3.4.0#-smart/4.26: Downloaded recipe revision 0
ERROR: opencv-ue4/3.4.0#smart/4.26: Cannot load recipe.
Error loading conanfile at '/home/user/.conan/data/opencv-ue4/3.4.0/smart/4.26/export/conanfile.py': /home/user/.conan/data/opencv-ue4/3.4.0/smart/4.26/export/conanfile.py not found!
Running ls -la /home/user/.conan/data/opencv-ue4/3.4.0/smart/4.26/export/ shows that the directory indeed contains only file conanmanifest.txt
Below is the relevant part of the conanfile.py that I've used to build the package
from conans import ConanFile, CMake, tools
class OpenCVUE4Conan(ConanFile):
name = "opencv-ue4"
version = "3.4.0"
url = ""
description = "OpenCV custom build for UE4"
license = "BSD"
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
exports_sources = 'patches/cmakes.patch', 'patches/check_function.patch', 'patches/typedefs.patch'
def requirements(self):
self.requires("ue4util/ue4#adamrehn/profile")
self.requires("zlib/ue4#adamrehn/{}".format(self.channel))
self.requires("UElibPNG/ue4#adamrehn/{}".format(self.channel))
def cmake_flags(self):
flags = [
"-DOPENCV_ENABLE_NONFREE=OFF",
# cut
]
return flags
def source(self):
self.run("git clone --depth=1 https://github.com/opencv/opencv.git -b {}".format(self.version))
self.run("git clone --depth=1 https://github.com/opencv/opencv_contrib.git -b {}".format(self.version))
def build(self):
# Patch OpenCV to avoid build errors
for p in self.exports_sources:
if p.endswith(".patch"):
tools.patch(base_path='opencv', patch_file=p, fuzz=True)
cmake = CMake(self)
cmake.configure(source_folder="opencv", args=self.cmake_flags())
cmake.build()
cmake.install()
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
Conan version both in Windows and in Linux is 1.54.0
How do I correctly upload and consume the package?
Update.
After conversation with #drodri in comments I have removed conanfile.py from exports_sources, deleted all conan-generated files in all PCs and removed uploaded files from the Artifactory.
Then I've rebuilt the package, re-exported and re-uploaded it.
The issue was in restrictions of our Artifactory. Admins have forbidden uploading .py files.

React Native, AzureDevops and Fastlane ipa build failing

I'm actually new to AzureDevOps and its been two days I can't seem to find a solution for building my app on AzureDevOps.
Here's what I've done so far:
p12 certificated uploaded and applied in pipeline following this guide Install Apple Certificate
provisioning certificate uploaded and applied in pipeline Install Apple Provisioning Certificate
Now when I try to build my iOS app using fastlane:
cd ios
bundle install
fastlane beta
setup_ci(force=true)
gym(scheme: 'app', workspace: './ios/workspace', verbose: true)
I'm looking for a way to use the p12 and provisioning profiles certificate from Azure DevOps to my gym build. After looking a lot, I found that setup_ci does that automatically for me.
Here is my Fastlane file
platform :ios do
lane :beta do
setup_ci(force=true)
gym(
scheme: 'AlfaCarpeting', workspace: './ios/AlfaCarpeting', verbose: true
)
end
end
And here's my Azure pipeline yml file:
# Node.js with React
# Build a Node.js project that uses React.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'macOS-10.15'
variables:
- group: React Native Variables
steps:
- task: InstallAppleCertificate#2
inputs:
certSecureFile: Certificates.p12
certPwd: $(P12Password)
keychain: 'temp'
deleteCert: true
displayName: Install Apple Certificate
- task: InstallAppleProvisioningProfile#1
inputs:
provisioningProfileLocation: 'secureFiles'
provProfileSecureFile: 'alfaCarpetingBeta.mobileprovision'
displayName: 'Install Apple Provisioning Profile'
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
cd ios
bundle install
fastlane ios beta
displayName: 'Build iOS'
The Logs from AzureDevops
[05:38:20]: $ set -o pipefail && xcodebuild -workspace ./AlfaCarpeting.xcworkspace -scheme AlfaCarpeting -destination 'generic/platform=iOS' -archivePath /Users/runner/Library/Developer/Xcode/Archives/2020-03-21/AlfaCarpeting\ 2020-03-21\ 05.38.20.xcarchive archive | tee /Users/runner/Library/Logs/gym/AlfaCarpeting-AlfaCarpeting.log | xcpretty
[05:38:22]: ▸ ❌ error: /Users/runner/runners/2.165.2/work/1/s/ios/Pods/Target Support Files/Pods-AlfaCarpeting/Pods-AlfaCarpeting.release.xcconfig: unable to open file (in target "AlfaCarpeting" in project "AlfaCarpeting") (in target 'AlfaCarpeting' from project 'AlfaCarpeting')
[05:38:22]: ▸ ❌ error: /Users/runner/runners/2.165.2/work/1/s/ios/Pods/Target Support Files/Pods-AlfaCarpeting/Pods-AlfaCarpeting.release.xcconfig: unable to open file (in target "AlfaCarpeting" in project "AlfaCarpeting") (in target 'AlfaCarpeting' from project 'AlfaCarpeting')
[05:38:22]: ▸ ❌ error: /Users/runner/runners/2.165.2/work/1/s/ios/Pods/Target Support Files/Pods-AlfaCarpeting/Pods-AlfaCarpeting.release.xcconfig: unable to open file (in target "AlfaCarpeting" in project "AlfaCarpeting") (in target 'AlfaCarpeting' from project 'AlfaCarpeting')
[05:38:22]: ▸ ❌ error: No profiles for 'com.AlfaCarpeting' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.AlfaCarpeting'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'AlfaCarpeting' from project 'AlfaCarpeting')
[05:38:22]: ▸ ** ARCHIVE FAILED **
If you open the project in xcode and goto Build Settings -> Signing you'll want to adjust the "Code Signing Style" to Manual. Here's the settings I ended up with (note - I am using fastlane match for cert and profile management):

RNC Slider lint FAILED on ./gradlew clean build and release apk crashes on app start

Before assembling release, I'm trying to make clean build but it throws error and fails the task. When I generate release apk (succesfully generates), after installing it on my LG G4 phone (also tried Samsung Galaxy J3), it is crashing and not starting.
My app succesfully works with react-native run-android on my phone.
Before assembling release build, I typed
cd android
./gradlew clean
./gradlew buildcache
./gradlew clean build
and the last command always gives errors.
After adding
android {
lintOptions {
abortOnError false
}
}
to RNC Slider's build.gradle file as the errors say, ./gradlew clean build succesfully finishes its task. But still I can't open the app after generating and installing release apk.
./gradlew clean build error:
...
> Task :#react-native-community_slider:lint FAILED
Ran lint on variant release: 3 issues found
Ran lint on variant debug: 3 issues found
Wrote HTML report to file:///D:/React/Pure%20RN/dassist/node_modules/#react-native-community/slider/android/build/reports/lint-results.html
Wrote XML report to file:///D:/React/Pure%20RN/dassist/node_modules/#react-native-community/slider/android/build/reports/lint-results.xml
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':#react-native-community_slider:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
Errors found:
D:\React\Pure RN\dassist\node_modules\#react-native-community\slider\android\src\main\java\com\reactnativecommunity\slider\ReactSliderManager.java:68: Error: Value must be ? 0 (was -2) [Range]
ViewGroup.LayoutParams.WRAP_CONTENT,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 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
BU¦LD FAILED in 35s
163 actionable tasks: 154 executed, 9 up-to-date
And this is a part of the xml report file (warnings excluded) mentioned in output logs:
<issues format="5" by="lint 3.3.1">
<issue
id="Range"
severity="Error"
message="Value must be ≥ 0 (was -2)"
category="Correctness"
priority="6"
summary="Outside Range"
explanation="Some parameters are required to in a particular numerical range; this check makes sure that arguments passed fall within the range. For arrays, Strings and collections this refers to the size or length."
errorLine1=" ViewGroup.LayoutParams.WRAP_CONTENT,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="D:\React\Pure RN\dassist\node_modules\#react-native-community\slider\android\src\main\java\com\reactnativecommunity\slider\ReactSliderManager.java"
line="68"
column="13"/>
</issue>
</issues>

REACT_NATIVE_MACOS - Error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER

Getting error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER in console log within xcode.
xcode version:Version 10.1 (10B61)
npm install react-native-macos-cli -g
react-native-macos init MyProject
cd MyProject
react-native-macos run-macos
(ie. straight out of the box)
Updated the xcode project preferences to include build/ in the location path. This got around code signing issues
However while doing the xcode build/run getting the following errors in the xcode console
2019-03-18 18:46:12.558858+1100 MyProject[33041:466498][BoringSSL] boringssl_context_alert_callback_handler(3724) [C1.1:2][0x100c22280] Alert level: fatal, description: protocol version
2019-03-18 18:46:12.558927+1100 MyProject[33041:466498] [BoringSSL] boringssl_context_error_print(3676) boringssl ctx 0x60000000a1e0: 4310761320:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.230.1/ssl/tls_record.cc:242:
2019-03-18 18:46:12.558959+1100 MyProject[33041:466498] [BoringSSL] boringssl_context_get_error_code(3581) [C1.1:2][0x100c22280] SSL_AD_PROTOCOL_VERSION
2019-03-18 18:46:12.562882+1100 MyProject[33041:466498] TIC TCP Conn Failed [1:0x600003709980]: 3:-9836 Err(-9836)

Generating signed APK not working: always generates unsigned apk

I want to generate a signed APK but I am not able to.
This is what I did:
Generated keystore file with this command:
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
Followed this guide:
https://facebook.github.io/react-native/docs/signed-apk-android.html#content
Generated APK with this command (on windows):
gradlew.bat assembleRelease
It always generates "app-release-unsigned.apk" file, do not why.
UPDATED
Solved, I forgot to add this line to app\build.gradle file:
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release // <--- ADD THIS LINE
}
}
did you add proper code in gradle.properties and build.gradle?
please mention your
build.gradle (App)
gradle.properties
file in question , and files of android/app/
it is possible that you does not have keystore file in directory android/app/
or have different name other than you mentioned in gradle.properties