最新消息:20210917 已从crifan.com换到crifan.org

【未解决】Android Studio中Project Structure提示错误:rootProject.compileSdkVersion Unresolved reference Resolved android-23

Android crifan 526浏览 0评论
折腾:
【未解决】Mac中用Android Studio打开rctjsa项目并编译apk和实时调试安卓手机小米9
期间,另外看到提示,去点击看看:
看到红色的:
unresolved Reference
resolved: android-23
感觉是:
设置的compile sdk version,不正确,无法解析
感觉和gradle配置:
build.gradle
中的:
project.ext.set("compileSdkVersion", 23)
有关系。
rootProject.compileSdkVersion Unresolved reference Resolved android-23
Android Studio unresolved reference. Project compiles – Stack Overflow
Kotlin中的Android项目编译出现 Unresolved reference: R 或者context、it 、entity解决_shenggaofei的博客-CSDN博客_unresolved reference: kotlinx
Kotlin Android应用程序编译失败的消息:未解决的引用:kotlinx。 – Kotlin Android App compilation failed with message: Unresolved reference: kotlinx – 开发者知识库
Kotlin Android App compilation failed with message: Unresolved reference: kotlinx – Stack Overflow
android – AndroidStudio/Kotlin – Unresolved reference: ReadWriteProperty – Kotlin version 1.0.0-beta-1038 – Stack Overflow
Gradle 提示与诀窍  |  Android 开发者  |  Android Developers
搞了半天,没搞懂此处问题所在
后来无意间点击 右边的小的下拉按钮,弹框后,才看到完整的错误提示:
Unresolved reference: $rootProject.compileSdkVersion
Unresolved reference rootProject.compileSdkVersion
如何解决Kotlin多平台android模块只能访问android api 1的问题? – 问答 – 云+社区 – 腾讯云
感觉都不对
应该是:此处的变量rootProject.compileSdkVersion
没有找到,无法解析才对
所以去找找
rootProject.compileSdkVersion
搜出来的都是和 统一配置管理
即统一版本,只需要设置一处 其他地方(子项目 子任务 )去引用 即可
Android Studio中用gradle统一版本 – 简书
说就是这个写法:
$rootProject.supportLibraryVersion
$rootProject.ext.junitVersion
不过好像是用ext的字典的写法:
ext {
    // Sdk and tools
    minSdkVersion = 15
    targetSdkVersion = 25
    compileSdkVersion = 25
    buildToolsVersion = '25.0.2'


    // App dependencies
    supportLibraryVersion = '25.1.0'
    guavaVersion = '18.0'
    junitVersion = '4.12'
    mockitoVersion = '1.10.19'
    powerMockito = '1.6.2'
    hamcrestVersion = '1.3'
    runnerVersion = '0.5'
    rulesVersion = '0.5'
    espressoVersion = '2.2.2'
}
和我此处的:
project.ext.set("compileSdkVersion", 23)
project.ext.set("minSdkVersion", 12)
project.ext.set("targetSdkVersion", 23)
//project.ext.set("buildToolsVersion", "24.0.0")
不一样。
所以或许是新gradle写法不同了?
Gradle for Android(二)全局设置、自定义BuildConfig、混淆 | 吴小龙同學
build.gradle
def androidSupportVersion = '25.3.1'
ext {
//编译的 SDK 版本,如API20
compileSdkVersion = 25
//构建工具的版本,其中包括了打包工具aapt、dx等,如API20对应的build-tool的版本就是20.0.0
buildToolsVersion = "26.0.0"
//兼容的最低 SDK 版本
minSdkVersion = 14
//向前兼容,保存新旧两种逻辑,并通过 if-else 方法来判断执行哪种逻辑
targetSdkVersion = 22
appcompatV7 = "com.android.support:appcompat-v7:$androidSupportVersion"
}
别处引用:
app/build.gradle
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.wuxiaolong.gradle4android"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
}
dependencies {
//……
compile rootProject.ext.appcompatV7
}
是写成:
rootProject.ext.compileSdkVersion
的。
所以:感觉此处应该需要改为:rootProject.ext.compileSdkVersion
gradle中统一配置版本的小技巧。 – 掘金
Android Studio中统一管理版本号引用配置_gao_chun-CSDN博客_android studio统一配置版本
Gradle 提示与诀窍  |  Android 开发者  |  Android Developers
是定义了:
buildscript {...}
allprojects {...}


// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
    // The following are only a few examples of the types of properties you can define.
    compileSdkVersion = 28
    // You can also use this to specify versions for dependencies. Having consistent
    // versions between modules can avoid behavior conflicts.
    supportLibVersion = "28.0.0"
    ...
}
...
后,去引用:
模块级 build.gradle
android {
  // Use the following syntax to access properties you define at the project level:
  // rootProject.ext.property_name
  compileSdkVersion rootProject.ext.compileSdkVersion
  ...
}
...
dependencies {
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    ...
}
即:rootProject.ext.compileSdkVersion
去改吧:
以为可以了。
但是实际上也不行。
算了,去改:
build.gradle
为ext的写法:
// project.ext.set("compileSdkVersion", 23)
// project.ext.set("minSdkVersion", 12)
// project.ext.set("targetSdkVersion", 23)
ext {
    compileSdkVersion = 23
    minSdkVersion = 12
    targetSdkVersion = 23
}
然后估计先要sync
然后再去看看:
竟然就解析出来了。
但是别的模块好像还不行:
不过点击弹框:
好像就可以刷新,解析出来了。
点击OK,看看
还是不行:
点击Apply试试:
然后再去看看:
还是:
只有第一个 module:RI 没问题:
其他还有问题:
发现了,是有些有问题:
有些没问题:
另外去别处看了看
看到Variable中有,我们新加的变量:
去删除掉:
$rootProject.compileSdkVersion
只保留系统的:
compileSdkVersion = 23
都改为了:
$compileSdkVersion
然后发现:
的确没红色报错了:
不过,之前不报错的
依旧可以识别出23
但是之前报错的,依旧没识别出23:
很是奇怪。
点击Apply,依旧报错:
突然想起来了:
此处应该是:
需要修改对应的子模块的配置?
然后此处编译也会报错
点击打开文件:
libs/api/build.gradle
apply plugin: 'com.android.library'


android {
    compileSdkVersion compileSdkVersion
//    buildToolsVersion rootProject.buildToolsVersion
发现被改了配置了。
改为:
android {
//    compileSdkVersion compileSdkVersion
    compileSdkVersion rootProject.ext.compileSdkVersion
结果:
问题依旧。
最后是:
把其他一共11个左右的子module,都改回上述,原来的值。
然后再去找到之前设置页面:
Open Module Settings
重新Apply去sync
结果始终报错:
【已解决】Android Studio中gradle报错:ERROR Cause compileSdkVersion is not specified
但是问题依旧:
搞得:不清楚:
上面这些 除了核心的RI,core,settings(三个对应的才有apk)的其他子模块
中上述红色未解析错误,是否:不算问题?可以不解决?
不过此处另外看到类似的:
settings中,其他tab:
Default config
中:
Target SDK version
中是:
$rootProject.targetSdkVersion
貌似有问题?
去改为:
$rootProject.ext.targetSdkVersion
以及:
$rootProject.minSdkVersion
改为:
$rootProject.ext.minSdkVersion
结果:
貌似没问题了?
但是实际上发现还是有问题:
点击Apply后,还是无法解析:
而同样配置的RI,就没问题:
所以目前感觉是:
不论是:
有些子模块:
$rootProject.targetSdkVersion
$rootProject.ext.targetSdkVersion

$rootProject.minSdkVersion
$rootProject.ext.minSdkVersion
哪种写法对,是否会报红色的解析错误
貌似暂时对项目编译 没啥影响?
暂时就忽略吧。
以后有机会再去尝试搞清楚。
【后记1】
注意到
android – Cause: compileSdkVersion is not specified – Stack Overflow
说的是:
apply plugin: ‘com.android.application’
以及官网
配置构建  |  Android 开发者  |  Android Developers
也是说了:
模块级的build.gradle
/**


apply plugin: 'com.android.application'
而我此处的是:
libs/api/build.gradle
apply plugin: 'com.android.library'
所以去改为:
apply plugin: 'com.android.application'
然后点击sync
报错很多:
ERROR: Unable to resolve dependency for ':notification@debug/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: notification
ERROR: Unable to resolve dependency for ':notification@debugAndroidTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: notification
ERROR: Unable to resolve dependency for ':notification@debugUnitTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: notification
ERROR: Unable to resolve dependency for ':core@debug/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: core
ERROR: Unable to resolve dependency for ':core@debugAndroidTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: core
ERROR: Unable to resolve dependency for ':core@debugUnitTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: core
ERROR: Unable to resolve dependency for ':cts_provider@debug/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: cts_provider
ERROR: Unable to resolve dependency for ':cts_provider@debugAndroidTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: cts_provider
ERROR: Unable to resolve dependency for ':cts_provider@debugUnitTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: cts_provider
ERROR: Unable to resolve dependency for ':tts@debug/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: tts
ERROR: Unable to resolve dependency for ':tts@debugAndroidTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: tts
ERROR: Unable to resolve dependency for ':tts@debugUnitTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: tts
ERROR: Unable to resolve dependency for ':settings@debug/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: settings
ERROR: Unable to resolve dependency for ':settings@debugAndroidTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: settings
ERROR: Unable to resolve dependency for ':settings@debugUnitTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: settings
ERROR: Unable to resolve dependency for ':api_cnx@debug/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: api_cnx
ERROR: Unable to resolve dependency for ':api_cnx@debugAndroidTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: api_cnx
ERROR: Unable to resolve dependency for ':api_cnx@debugUnitTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: api_cnx
ERROR: Unable to resolve dependency for ':RI@debug/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: RI
ERROR: Unable to resolve dependency for ':RI@debugAndroidTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: RI
ERROR: Unable to resolve dependency for ':RI@debugUnitTest/compileClasspath': Could not resolve project :api.
Show Details
Affected Modules: RI
算了,保留:
apply plugin: 'com.android.library'
apply plugin: 'com.android.application'
结果:
ERROR: Android Gradle plugin 3.5.4 must not be applied to project '/Users/xxx/dev/xxx/RCS/rcsjta/libs/api' since version 3.5.4 was already applied to this project
Open File
算了,去掉application,恢复原先内容吧
apply plugin: 'com.android.library'
//apply plugin: 'com.android.application'
以后有空再说。

转载请注明:在路上 » 【未解决】Android Studio中Project Structure提示错误:rootProject.compileSdkVersion Unresolved reference Resolved android-23

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.206 seconds, using 23.41MB memory