React-Native Android generate Signed apk: Build Gradle error - react-native

Build.gradle error on Line 2.
I followed the steps described in https://facebook.github.io/react-native/releases/0.31/docs/signed-apk-android.html
// Top-level build file where you can add configuration options common to all sub-projects/modules.
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
Can someone please point out where I went wrong?

You are working in android/build.gradle, but you are supposed to add those lines in android/src/build.gradle.

Related

Missing plugin in `eas build` of react-native project

I am in the process of trying to build a preview Android version using EAS build, but when I run eas build -p android --profile android-preview I get this error:
[stderr] A problem occurred evaluating project ':unimodules-core'.
[stderr] >
[stderr] Plugin with id 'maven' not found.
Now I see people are suggesting replacing this:
apply plugin: 'maven'
With this, in the build.gradle file:
apply plugin: 'maven-publish'
But I don't find that reference to maven anywhere in my project. And my build.gradle file looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '31.0.0'
minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '21')
compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '31')
targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '31')
if (findProperty('android.kotlinVersion')) {
kotlinVersion = findProperty('android.kotlinVersion')
}
frescoVersion = findProperty('expo.frescoVersion') ?: '2.5.0'
kotlinVersion: '1.6.20'
if (System.properties['os.arch'] == 'aarch64') {
// For M1 Users we need to use the NDK 24 which added support for aarch64
ndkVersion = '24.0.8215888'
} else {
// Otherwise we default to the side-by-side NDK version from AGP.
ndkVersion = '21.4.7075529'
}
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath('com.android.tools.build:gradle:7.2.1')
classpath('com.facebook.react:react-native-gradle-plugin')
classpath('de.undercouch:gradle-download-task:5.0.1')
classpath('org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
def REACT_NATIVE_VERSION = new File(['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android'))
}
maven {
// Android JSC is installed from npm
url(new File(['node', '--print', "require.resolve('jsc-android/package.json')"].execute(null, rootDir).text.trim(), '../dist'))
}
google()
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup 'com.facebook.react'
}
}
maven { url 'https://www.jitpack.io' }
}
}
How can I resolve this? Any help would be appreciated.

Android dependency 'com.google.firebase:firebase-iid' has different version for the compile (16.0.0) and runtime (18.0.0) classpath

In my react native application i am integrating react-native-push-notification and getting this error.
app/build.gradle
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "xxxxxxx"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-push-notification')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:23.0.1"
implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
Project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:4.0.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
google()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.0.2"
}
}
}
}
I tried various solutions like changing from "implementaion" to "api" , in configuration.all adding check to fetch particular version of firebase-core, but nothing worked.
React Native version is 0.55.4
I found the solution.
In my project's build.gradle buildscript->dependencies i replaced version of the google-services gradle plugin from "4.0.2" to "4.2.0" and it worked.
classpath 'com.google.gms:google-services:4.2.0'
The library react-native-push-notification has a dependency declared as '+' for the com.google.firebase:firebase-messaging in it's build.gradle. This will fetch the latest version of the library from maven repo.
This is clashing with your version declaration in your android/app/build.gradle file, which is 16.0.1.
Add this to your project level build.gradle
ext {
googlePlayServicesVersion = "[your_desired_version]"
firebaseVersion = "[your_desired_version]"
}

A problem occurred configuring project ':app'

Getting error when trying react-native run-android.I don't know why I'm getting this error.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApk'.
> A problem occurred configuring project ':react-native-vector-icons'.
> Could not resolve all dependencies for configuration ':react-native-vector-icons:classpath'.
> Could not find any matches for com.android.tools.build:gradle:2.3.+ as no versions of com.android.tools.build:gradle are available.
android\build.gradle is as follows.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is
installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
gradle version: 3.3,
plugin:2.2.3
Upgrade react-native-vector-icons: "^6.0.2" in package.json
Then run npm i react-native-vector-icons
As a last step, cd android && ./gradlew clean.
Change dependencies from:
dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
}
to:
dependencies {
compile "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
}
also change buildscript dependencies to use: classpath 'com.android.tools.build:gradle:2.2.3'
and maven { url "https://dl.bintray.com/android/android-tools/" } instead of google()
So your ../node_modules/react-native-vector-icons/android/build.gradle should look like this:
buildscript {
repositories {
maven { url "https://dl.bintray.com/android/android-tools/" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.library'
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
android {
compileSdkVersion safeExtGet('compileSdkVersion', 26)
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
mavenCentral()
}
dependencies {
compile "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
}

React native build cannot find jar

We have a project, which compiles and run for everybody EXCEPT me. I have exactly the same code, I try to run it exactly the same way, but the log says:
FAILURE: Build failed with an exception.
What went wrong: Could not resolve all files for configuration ':react-native-camera:debugCompileClasspath'.
> Could not find core.jar (com.google.zxing:core:3.3.0). Searched in the following locations:
https://artifactory.mycompany.eu/artifactory/mvn-libs-all/com/google/zxing/core/3.3.0/core-3.3.0.jar
I changed the url above (only the company name), but i checked, and the jar is presented there.
This jar is necessary for react-native-camera node module.
I have already:
run npm cache clean --force
run gradlew clean
deleted the whole project, checked out the source code, installed
node modules, tried to run
But nothing helped.
EDIT:
project/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
rootProject.ext.isRelease = project.hasProperty('buildForDebug')? false:true
def RNfile = new File("$rootDir/node_modules/react-native/package.json")
rootProject.ext.rnVersion = new groovy.json.JsonSlurper().parseText(RNfile.text).version
artifactId = project.artifactId
allprojects {
println "release $isRelease"
//version = "${project.version}-${isRelease ? project.property('build.number') : 'SNAPSHOT'}"
version = "${project.version}-${ project.hasProperty('build.number') ? project.property('build.number') : '0'}"
group = project.groupId
println "coordinates: $group:$artifactId:$version"
}
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
}
}
allprojects {
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
details.useVersion rootProject.ext.rnVersion
}
}
}
}
repositories {
mavenLocal()
google()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/node_modules/react-native/android"
}
}
}
subprojects { project ->
afterEvaluate {
if (project.name.contains('react-native-')) {
project.tasks.collect { task ->
if (task.name == 'lint') {
task.enabled = false
}
}
}
}
}
project/android/app/build.gradle
project.ext.androidSignKeystorePassword = (project.hasProperty('keystorePassword'))? project.property('keystorePassword') : System.properties['android.keystorePassword']
project.ext.androidSignKeyPassword = (project.hasProperty('keyPassword'))? project.property('keyPassword') : System.properties['android.keyPassword']
project.ext.androidSignKeyAlias = (project.hasProperty('keyAlias'))? project.property('keyAlias') : System.properties['android.keyAlias']
configurations {
keystore
}
dependencies {
keystore "eu.dorsum.cm.config:jenkins-android-keystore:1#jks"
}
rootProject.ext.signApp = project.hasProperty('signKeyAlias') && project.hasProperty('keystore-android-password')
buildscript {
repositories {
google()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.google.gms:google-services:4.1.0'
}
}
allprojects {
repositories {
mavenLocal()
google()
maven {
url "https://maven.google.com"
}
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
details.useVersion rootProject.ext.rnVersion
}
}
}
}
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}
}
}
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
import com.android.build.OutputFile
project.ext.react = [
root: "$rootDir",
entryFile: "index.js"
]
apply from: "$rootDir/node_modules/react-native/react.gradle"
apply from: "$rootDir/node_modules/react-native-vector-icons/fonts.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.dbit"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName project.version
ndk {
abiFilters "armeabi-v7a", "x86"
}
if (!project.hasProperty('buildForDebug')) {
archivesBaseName = "${rootProject.name}-${versionName}"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
storeFile files(project.configurations.keystore.collect { it }).singleFile
storePassword project.ext.androidSignKeystorePassword
keyAlias project.ext.androidSignKeyAlias
keyPassword project.ext.androidSignKeyPassword
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
}
}
variantFilter { variant ->
// ignores unwanted build types
// no release type from development branch, no debug type from release branch
// (ignore = release type XOR release version)
setIgnore(variant.buildType.name.equals('release') ^ isRelease)
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation project(':react-native-view-overflow')
implementation project(':react-native-vector-icons')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-fcm')
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-messaging'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.0.3"
implementation "com.facebook.react:react-native:${rootProject.ext.rnVersion}" // From node_modules
implementation (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
implementation 'com.android.support:exifinterface:27.1.0'
implementation ('com.google.android.gms:play-services-vision:12.0.1') {
force = true
}
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.implementation
into 'libs'
}
If you have any suggestion, it would be highly appreciated.
I think you miss repository in Gradle to get com.google.zxing:core:3.3.0
You need open Android Studio with project in folder /android of your react-native project.
and edit file build.gradle of project
like this
and add google() and jcenter() to respository of buildscript and allprojects
like this
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
In my case the solution was running the following command in the projectName/android folder:
gradlew cleanBuildCache
The strange thing for me is that gradlew clean was not enough.
According to this documentation https://developer.android.com/studio/build/build-cache#clear_the_build_cache:
"Similar to the Android plugin's clean task that clears your project’s
build/ directories, you can run the cleanBuildCache task to clear your
project’s build cache."
Based on this information, it is obvious that something went wrong in my build cache and that caused the problem.
I also had to delete the node_modules folder, and install all node modules again.

Google Play Services Ads?

I cant add android studio App Admob to an app.
grandle Could not download this
'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/3.1.1/google-services-3.1.1.pom'.
Could not GET 'https://jcenter.bintray.com/com/google/gms/google-services/3.1.1/google-services-3.1.1.pom'.
Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
SCREENSHOTS
SCREENSHOTS1
SCREENSHOTS2
SCREENSHOTS3
SCREENSHOTS4
SCREENSHOTS5