gpt4 book ai didi

java - 由于 SDK_INT 和 VERSION_CODES.P 无法构建 Android APK - 那是什么?

转载 作者:行者123 更新时间:2023-12-01 19:37:27 27 4
gpt4 key购买 nike

尝试发布适用于 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 下载了以下组件:

  • API 27
  • API 28
  • Android SDK 构建工具 29
  • Android 模拟器
  • Android SDK 平台工具
  • Android SDK 工具
  • 支持存储库

我尝试了几次清理gradle缓存,但没有成功。我是java新手,不知道如何处理这个问题。

有什么想法吗?

<小时/>

将compileSdkVersion更改为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.

最佳答案

您的 compileSdkVersion 是 27,但 Android P 的 API 是 28。如果您想使用 Android P 特定的 API,则需要将 compileSdkVersion 设置为 28,例如作为 Build.VERSION_CODES.P 常量,仅在 Android P 中引入。

根据 this blog post ,您应该始终寻求使用最新的 SDK 进行编译(无论您是否使用该 API 级别的任何功能)。

Migration to AndroidX 之前,如果您使用的支持库版本与您的 compileSdkVersion 不匹配,Lint 确实会提示。您可以忽略它,也可以升级到 28.0.0,这是迁移到 AndroidX 之前的最后一个版本。

关于java - 由于 SDK_INT 和 VERSION_CODES.P 无法构建 Android APK - 那是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56925604/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com