can't build project after installing react native contacts - react-native

after installing the "react-native contacts" i get error in run time and it cant download gardle 4.1.0, so what i did just running command "npm i react-native-contacts" and my project config is like below:
pachage.json
"react-native": "0.68.1",
"react-native-contacts": "^7.0.5",
gardel.build:
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
and the error is this:
Could not resolve all files for configuration ':react-native-contacts:classpath'.
> Could not find gradle-4.1.0.jar (com.android.tools.build:gradle:4.1.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.jar
i tried proxy to download it but it not works, i event could download it by browser(by the way im in iran, don't know if it related)

I'm in Portugal and the link to the .jar works in my browser.

Related

Plugin [id: 'com.android.application', version: '7.4.2', apply: false] was not found in any of the following sources:

I'm a new coder...
I installed Android Studio through offline mode. Sdk related things were done but there were some gradle problems. Actually I couldn't figure out the problem.
Here's my build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here's my gradle.wrapper.propperties
#Sun Jun 26 11:20:58 IRDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Here's the error itself:
Build file 'C:\Users\Mostafa\AndroidStudioProjects\1\build.gradle' line: 3
Plugin [id: 'com.android.application', version: '7.4.2', apply: false] was not found in any of the following sources:
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version:
'7.4.2', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact
'com.android.application:com.android.application.gradle.plugin:7.4.2')
Searched in the following repositories:
Gradle Central Plugin Repository
Google

npm - gulp-sass no longer has a default Sass compiler; please set one yourself

Keep getting this error when trying to build templates
[09:21:08] Requiring external module babel-register
[09:21:19] Using gulpfile ~/GIT/Newsletters/gulpfile.babel.js
[09:21:19] Starting 'build'...
[09:21:19] Starting 'clean'...
[09:21:19] Finished 'clean' after 5.98 ms
[09:21:19] Starting 'pages'...
[09:21:20] Finished 'pages' after 1.96 s
[09:21:20] Starting 'sass'...
Error in plugin "gulp-sass"
Message:
gulp-sass no longer has a default Sass compiler; please set one yourself.
Both the "sass" and "node-sass" packages are permitted.
For example, in your gulpfile:
const sass = require('gulp-sass')(require('sass'));
When I then add const sass = require('gulp-sass')(require('sass')); in my gulpfile.js
It gives this error
[09:41:01] Requiring external module babel-register
{ TypeError: /Users/lde4k1v/GIT/Newsletters/gulpfile.babel.js: Duplicate declaration "sass"
76 |
77 | // Compile Sass into CSS
> 78 | function sass() {
| ^
79 | return gulp.src('src/assets/scss/app.scss')
80 | .pipe($.if(!PRODUCTION, $.sourcemaps.init()))
81 | .pipe($.sass({
Here is my full gulpfile.babel.js
Can someone help me out :( already searched quite some time on it and can't find seem to fix it sadly

generate release apk in 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 :)

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>

Xcode build error: PhaseScriptExecution Strip\ Frameworks /appName.build/Debug-iphonesimulator/PROD.build/Script-8CBD27422B744FC9C0407AA3.sh

I am really struggling to understand the internals of Xcode, the latest error I am getting is this one:
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Strip\ Frameworks /Users/danale/Library/Developer/Xcode/DerivedData/build/Build/Intermediates.noindex/NFIBEngage.build/Debug-iphonesimulator/PROD.build/Script-8CBD27422B744FC9C0407AA3.sh
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/NFIBEngage.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/NFIBEngage.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
How do I go about resolving this? None of what I have seen thus far has worked. The application itself loads just fine inside of simulator, but I keep getting build failures.
I was getting this error when I had React Native 0.53.3 and React 16.2 and I continue to get this error when I upgraded to React Native 0.59.9 and React 16.8.
The PhaseScriptExecution Strip\ Frameworks /appName.build/Debug-iphonesimulator/PROD.build/Script-8CBD27422B744FC9C0407AA3.sh Xcode build error was related to some configuration inside of ios/Pods/Pods.xcodeproj/project.pbxproj where the configuration in those files look something like this:
9B41C3B09EAC07B2B007DE0F /* Strip Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Strip Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "bash \"${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/InstabugCore.framework/strip-frameworks.sh\"\n";
};
Once I completely removed references to 8CBD27422B744FC9C0407AA3 the error went away.