Reputation: 1831
It's been two sad days trying to release my React Native app for Android, but getting this error:
> Task :react-native-device-info:compileReleaseJavaWithJavac FAILED
/Users/myuser/project/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java:368: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
^
symbol: variable P
location: class VERSION_CODES
/Users/myuser/project/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java:370: error: cannot find symbol
locationEnabled = mLocationManager.isLocationEnabled();
^
symbol: method isLocationEnabled()
location: variable mLocationManager of type LocationManager
Note: /Users/myuser/project/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
FAILURE: Build failed with an exception.
My project/android/build.gradle
file is:
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 23
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
playServicesVersion = "16.0.0"
}
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
mavenLocal()
google()
maven {
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
}
}
afterEvaluate {
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
targetSdkVersion 27
}
}
}
}
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 27
supportLibVersion = "27.1.0"
}
Also, my Android Studio has the following components downloaded:
I tried several times cleaning gradle cache, but no success. I'm a newbie on java and have no idea on how to deal with this.
Any idea?
After changing compiledSdkVersion to 28, now I'm getting the following errors:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':app:releaseCompileClasspath'.
> Could not resolve android.arch.lifecycle:viewmodel:1.1.0.
Required by:
project :app
> Cannot find a version of 'android.arch.lifecycle:viewmodel' that satisfies the version constraints:
Dependency path 'MobileApp:app:unspecified' --> 'com.android.support:appcompat-v7:28.0.0' --> 'com.android.support:support-fragment:28.0.0' --> 'android.arch.lifecycle:viewmodel:1.1.1'
Constraint path 'MobileApp:app:unspecified' --> 'android.arch.lifecycle:viewmodel' strictly '1.1.0' because of the following reason: releaseRuntimeClasspath uses version 1.1.0
Constraint path 'MobileApp:app:unspecified' --> 'android.arch.lifecycle:viewmodel' strictly '1.1.0' because of the following reason: releaseRuntimeClasspath uses version 1.1.0
Constraint path 'MobileApp:app:unspecified' --> 'android.arch.lifecycle:viewmodel' strictly '1.1.0' because of the following reason: releaseRuntimeClasspath uses version 1.1.0
> Could not find com.android.support:collections:27.1.1.
Required by:
project :app > com.android.support:appcompat-v7:28.0.0
project :app > com.android.support:support-compat:28.0.0
> Could not find com.android.support:cursoradapter:27.1.1.
Required by:
project :app > com.android.support:appcompat-v7:28.0.0
> Could not find com.android.support:loader:27.1.1.
Required by:
project :app > com.android.support:support-fragment:28.0.0
project :app > com.android.support:support-core-utils:28.0.0
> Could not resolve android.arch.lifecycle:viewmodel:1.1.1.
Required by:
project :app > com.android.support:support-fragment:28.0.0
> Cannot find a version of 'android.arch.lifecycle:viewmodel' that satisfies the version constraints:
Dependency path 'MobileApp:app:unspecified' --> 'com.android.support:appcompat-v7:28.0.0' --> 'com.android.support:support-fragment:28.0.0' --> 'android.arch.lifecycle:viewmodel:1.1.1'
Constraint path 'MobileApp:app:unspecified' --> 'android.arch.lifecycle:viewmodel' strictly '1.1.0' because of the following reason: releaseRuntimeClasspath uses version 1.1.0
Constraint path 'MobileApp:app:unspecified' --> 'android.arch.lifecycle:viewmodel' strictly '1.1.0' because of the following reason: releaseRuntimeClasspath uses version 1.1.0
Constraint path 'MobileApp:app:unspecified' --> 'android.arch.lifecycle:viewmodel' strictly '1.1.0' because of the following reason: releaseRuntimeClasspath uses version 1.1.0
> Could not find com.android.support:versionedparcelable:27.1.1.
Required by:
project :app > com.android.support:support-compat:28.0.0
> Could not find com.android.support:documentfile:27.1.1.
Required by:
project :app > com.android.support:support-core-utils:28.0.0
> Could not find com.android.support:localbroadcastmanager:27.1.1.
Required by:
project :app > com.android.support:support-core-utils:28.0.0
> Could not find com.android.support:print:27.1.1.
Required by:
project :app > com.android.support:support-core-utils:28.0.0
UPDATE 3
After changing details.useVersion
to 28.0.0
I'm now getting this error:
> Task :app:bundleReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture fingerprint of input files for task ':app:bundleReleaseJsAndAssets' property '$1' during up-to-date check.
> Could not list contents of '/Users/myuser/myproject/node_modules/metro/node_modules/jest-haste-map/node_modules/.bin/sane'. Couldn't follow symbolic link.
Upvotes: 1
Views: 6413
Reputation: 200080
Your compileSdkVersion
is 27, but Android P is API 28. You need to set your compileSdkVersion
to 28 if you'd like to use Android P specific APIs, such as the Build.VERSION_CODES.P
constant, which was only introduced in Android P.
As per this blog post, you should always seek to compile with the latest SDK (whether you use any features of that API level or not).
Prior to the Migration to AndroidX, Lint does complain if you use a Support Library version that does not match your compileSdkVersion
. You can either ignore it, or upgrade to 28.0.0
, which was the last release prior to moving to AndroidX.
Upvotes: 6