尝试发布适用于Android的React Native应用程序已经过了两个悲伤的日子,但出现此错误:
> 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.
我的project/android/build.gradle
文件是:
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"
}
此外,我的Android Studio已下载了以下组件:
我尝试了几次清理gradle缓存,但是没有成功。 我是Java的新手,对如何处理它一无所知。
有什么主意吗?
将compiledSdkVersion更改为28之后,现在出现以下错误:
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
更新3
将details.useVersion
更改为28.0.0
后,现在出现此错误:
> 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.
答案 0 :(得分:3)
您的compileSdkVersion
是27,而Android P是API28。如果您想使用Android P特定的API,例如{{1},则需要将compileSdkVersion
设置为28。 }常量,仅在Android P中引入。
根据this blog post,您应始终寻求使用最新的SDK进行编译(无论是否使用该API级别的任何功能)。
在Migration to AndroidX之前,如果您使用的支持库版本与Build.VERSION_CODES.P
不匹配,则Lint会抱怨。您可以忽略它,也可以升级到compileSdkVersion
,这是移至AndroidX之前的最新版本。