Cannot compile react-native-expo project - react-native

So i have a bare react-native application wherein i am using expo modules.
I am using the expo location module and getting the following error.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/LocationModule.java:361: error: cannot find symbol
new Permissions.PermissionsRequestListener() {
^
symbol: class PermissionsRequestListener
location: interface Permissions
/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/LocationModule.java:502: error: cannot find symbol
mPermissions.getPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
^
symbol: method getPermission(String)
location: variable mPermissions of type Permissions
/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/LocationModule.java:503: error: cannot find symbol
&& mPermissions.getPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
^
symbol: method getPermission(String)
location: variable mPermissions of type Permissions
Note: /home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/expo-location/android/src/main/java/expo/modules/location/taskConsumers/GeofencingTaskConsumer.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':expo-location:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* 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
BUILD FAILED in 16s
at checkExecSyncError (child_process.js:607:13)
at execFileSync (child_process.js:627:13)
at runOnAllDevices (/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
at buildAndRun (/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
at then.result (/home/amol/Desktop/AccountantComplete/CompleteCode/Accountant/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7);
So my best guess is there is an error while importing stuff from permission module.
So i have these lines in expo-permissions app level build.gradle file.
compileOnly('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
I am also using jettifier, i am guessing there is some issue with respect to transpiling code to android x.
I changed this
compileOnly('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
to
implementation 'com.facebook.react:react-native:+'
and everything works fine.
I would like to know exactly what is happening and if this deserves a pull request.
Any help on the same would be highly appreciated thanks.

ok, in my case I needed to raise the following versions from android/build.grade:
buildscript {
ext {
buildToolsVersion = "28.0.3" -> "29.0.2"
minSdkVersion = 21
compileSdkVersion = 28 -> 29
targetSdkVersion = 28 -> 29
}

Related

Getting an error with react-native-safe-area-context build.gradle file and compileSdkVersion is not specified

I am getting this Error message while building my react native project.
BUILD FAILED in 4s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\sawan\OneDrive\Desktop\Unsplash\app\node_modules\react-native-safe-area-context\android\build.gradle' line: 28
* What went wrong:
A problem occurred evaluating project ':react-native-safe-area-context'.
> Could not initialize class org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':react-native-safe-area-context'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle
* 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.
==============================================================================
Its saying error is in this file:
C:\Users\sawan\OneDrive\Desktop\Unsplash\app\node_modules\react-native-safe-area-context\android\build.gradle
//rest of the code ...
android {
compileSdkVersion getExtOrDefault('compileSdkVersion', 30)
// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
ndkVersion rootProject.ext.ndkVersion
}
defaultConfig {
minSdkVersion getExtOrDefault('minSdkVersion', 16)
targetSdkVersion getExtOrDefault('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
ndk {
abiFilters (*reactNativeArchitectures())
}
}// rest of the code ....
Here is my build.gradle file from \android
buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"
// kotlin_version = '1.5.20' //
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.3.1")
classpath("com.facebook.react:react-native-gradle-plugin")
// classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") //
}}
Don't know if error is in this path or the build.gradle file

KMM in Android Studio build return Command PhaseScriptExecution failed with a nonzero exit code

I've just created a new KMM project through out KMM Plugin, but I can't run or even debug in Xcode iosApp part of the project. When I try to run iosApp from Android Studio, the build process fails (Command PhaseScriptExecution failed with nonzero exit code)
The final lines of building was:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':shared:compileKotlinIosX64'.
Compilation finished with errors
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
BUILD FAILED in 8s
1 actionable task: 1 executed
Command PhaseScriptExecution failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Run\ Script /Users/tamegajr/AndroidStudioProjects/TesteKMM5/build/ios/iosApp.build/Release-iphonesimulator/iosApp.build/Script-7555FFB5242A651A00829871.sh
(1 failure)
Can anyone help to solve this problem?
I had the same issue but this solution helped me:
From KMM pluging you will obtain (on dependencies):
Change this:
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
To this:
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
What i found to be the solution was to uncomment the "iosSimulatorArm64()" in the "build.gradle.kts(:shared)".
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64() //sure all ios dependencies support this target
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosLink/Podfile")
framework {
baseName = "shared"
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
}
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val iosX64Test by getting
val iosArm64Test by getting
//val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
//iosSimulatorArm64Test.dependsOn(this)
}
}
}
After some code review from 2-3 months old KMM examples project and comparing them with new ones, I found out a solution for this build failure when trying to run iosApp on Ios Simulators, just apply this change to build.gradle.kts on root project:
From KMM pluging you will obtain (on dependencies):
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
Change it to:
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
And that's it, problem solve. I hope someone on Jetbrains can solve this problem in future updates of KMM plugin.
08/30/2020:
It seems that Jetbrains has correct some issues and now you can build and run a KMM project with version 1.7.10, the last stable version at this time.
By the way, if you have any trouble is worthy to check this stack overflow post about JDK version used by Android Studio : How to set or change the default Java (JDK) version on macOS?
Multiplatform error when building iosApp: Command PhaseScriptExecution failed with a nonzero exit code

Unresolved reference: protoc - when using Gradle + Protocol Buffers

I have a gradle project which uses the Kotlin DSL
build.gradle.kts
plugins {
kotlin("jvm") version "1.4.21"
id("com.google.protobuf") version "0.8.10"
}
group = "schema"
version = "0.0.1-SNAPSHOT"
repositories {
mavenCentral()
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.0.0"
}
}
schema.proto
syntax = "proto3";
package schema;
message Message {
string content = 1;
string date_time = 2;
}
and project structure
schema
-src/main/proto/schema.proto
-build.gradle.kts
Whenever I run gradle build I get error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/x/schema/build.gradle.kts' line: 13
* What went wrong:
Script compilation errors:
Line 15: protoc {
^ Unresolved reference: protoc
Line 16: artifact = "com.google.protobuf:protoc:3.0.0"
^ Unresolved reference: artifact
* 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
BUILD FAILED in 8s
The only thing I am doing different to various tutorials is using the Gradle Kotlin DSL. What am I doing wrong?
I think this is happening because you are referencing a single task within the protobuf gradle plugin. Try importing the whole bundle to make use of type-safe accessors as you desired.
import com.google.protobuf.gradle.*
For whatever reason this works
import com.google.protobuf.gradle.protoc
protobuf {
protobuf.protoc {
artifact = "com.google.protobuf:protoc:3.0.0"
}
}
It seems a little ugly having to specify protobuf twice mind

Compile error while react-native-maps building

I'm new to react-native and I'm keeping getting an error while trying to build with react-native-maps.
Steps I made:
react-native init --version="0.57.4" <my_app_name>
cd <my_app_name>
react-native install react-native-geocoder
react-native install react-native-maps
react-native run-android
Error message:
> Task :react-native-maps:compileDebugJavaWithJavac
Note: Some input files use or override 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 :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: android.support.v4.app.ActivityCompat
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
Following instructions from #samitha-nanayakkara, I've reached this issue, I did try to delete the build directories each time and edit android/app/build.gradle like:
defaultConfig {
...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
That give me the error message:
> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: android.support.v4.app.ActivityCompat
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
Also, trying Java 8 give me the same result:
defaultConfig {
...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Adding multiDexEnabled true to android/app/build.gradle give me another error message:
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. > com.android.build.api.transform.TransformException: Error while generating the main dex list.
How could I solve this?

using react-native build android apk

i build react-native for android apk has error, need you help!
error info:
C:\Users\Chris.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\5934c37098d7fc1d388cdfd621f50e8f\res\values-v24\values-
v24.xml:3:5-157: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Mater
ial.Widget.Button.Borderless.Colored'.
C:\Users\Chris.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\5934c37098d7fc1d388cdfd621f50e8f\res\values-v24\values-
v24.xml:4:5-135: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Mater
ial.Widget.Button.Colored'.
C:\Users\Chris.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\5934c37098d7fc1d388cdfd621f50e8f\res\values-v26\values-
v26.xml:13:5-16:13: AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processReleaseResources'.
Failed to process resources, see aapt output above for details.
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 ge
t full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1m 50s
94 actionable tasks: 2 executed, 92 up-to-date
config info :
...
android {
compileSdkVersion 25
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.helloworld"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
manifestPlaceholders = [
JPUSH_APPKEY: "01e91c7c174c2c6888228f25",
APP_CHANNEL : "default"
]
...
ndk {
abiFilters "armeabi-v7a", "x86"
}
}