gpt4 book ai didi

Android Studio : unresolved reference for java and javax imports, 但项目编译

转载 作者:行者123 更新时间:2023-12-03 05:23:42 30 4
gpt4 key购买 nike

我正在尝试在 Android Studio 项目中创建自己的注释处理器。
我在 Android Studio 中为此创建了另一个模块.
我能够编译该项目。我不能只使用自动完成和其他东西。在这种情况下,IDE 将所有引用视为 Unresolved 引用错误
enter image description here
我该如何解决这个问题?
什么是重要的
当我默认创建新的库模块“autoadapter-process”时,Android Studio 在 build.gradle 中为这个模块创建了这个实现:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
为了能够编译项目,我将其替换为:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
下面是我在项目结构 (Android Studio) 中的 JDK 设置:
enter image description here
下面是我的项目结构:
enter image description here
这是我的自动适配器处理器模块的 Gradle 配置:
apply plugin: 'java-library'
apply plugin: 'kotlin'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':autoadapter-annotations')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
这个 https://stackoverflow.com/a/61180376/104891 问题与我的不同,因为它是 IntelliJ IDEA 特定的。它不是 Android Studio 特定的 .

最佳答案

看来,Android Studio 缓存了为新的 Android Studio 版本导入的一些先前设置。当我可能从版本 3.1 -> 3.2 -> 3.4 -> ... -> 4.0 更新时,我已经做了很长时间了
所以旧的JDK版本似乎缓存在里面jdk.table.xml 文件
只要找到您的 Android Studio 选项文件夹,您就可以在其中找到此文件(在我的情况下,它是 User/Library/Preferences/AndroidStudio4.0/options)
您可以删除它并使用正确的版本再次创建它(这对我有用并且是我的问题的解决方案:
https://stackoverflow.com/a/38067170/5434346
或者你可以尝试修改它(我没试过):https://stackoverflow.com/a/41531367/5434346
奇怪的是它没有包含任何 JDK 1.7 引用:

<application>
<component name="ProjectJdkTable">
<jdk version="2">
<name value="1.8" />
<type value="JavaSDK" />
<version value="java version &quot;1.8.0_152-release&quot;" />
<homePath value="$APPLICATION_HOME_DIR$/jre/jdk/Contents/Home" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/lib/jdkAnnotations.jar!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/charsets.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/cldrdata.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/dnsns.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/jaccess.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/localedata.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/nashorn.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/sunec.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/ext/zipfs.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/jce.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/jsse.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/management-agent.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/resources.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/jre/lib/rt.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/lib/dt.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/lib/jconsole.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/lib/sa-jdi.jar!/" type="simple" />
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home/lib/tools.jar!/" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite">
<root url="http://docs.oracle.com/javase/8/docs/api/" type="simple" />
</root>
</javadocPath>
<sourcePath>
<root type="composite" />
</sourcePath>
</roots>
<additional />
</jdk>
<jdk version="2">
<name value="Android API 27 Platform" />
<type value="Android SDK" />
<version value="java version &quot;1.8.0_152-release&quot;" />
<homePath value="$USER_HOME$/Library/Android/sdk" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/plugins/android/lib/androidAnnotations.jar!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar://$USER_HOME$/Library/Android/sdk/platforms/android-27/android.jar!/" type="simple" />
<root url="file://$USER_HOME$/Library/Android/sdk/platforms/android-27/data/res" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite">
<root url="http://developer.android.com/reference/" type="simple" />
</root>
</javadocPath>
<sourcePath>
<root type="composite" />
</sourcePath>
</roots>
<additional jdk="1.8" sdk="android-27" />
</jdk>
<jdk version="2">
<name value="Android API 25 Platform" />
<type value="Android SDK" />
<version value="java version &quot;1.8.0_152-release&quot;" />
<homePath value="$USER_HOME$/Library/Android/sdk" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/plugins/android/lib/androidAnnotations.jar!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar://$USER_HOME$/Library/Android/sdk/platforms/android-25/android.jar!/" type="simple" />
<root url="file://$USER_HOME$/Library/Android/sdk/platforms/android-25/data/res" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite">
<root url="http://developer.android.com/reference/" type="simple" />
</root>
</javadocPath>
<sourcePath>
<root type="composite" />
</sourcePath>
</roots>
<additional jdk="1.8" sdk="android-25" />
</jdk>
<jdk version="2">
<name value="Android API 26 Platform" />
<type value="Android SDK" />
<version value="java version &quot;1.8.0_152-release&quot;" />
<homePath value="$USER_HOME$/Library/Android/sdk" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar://$APPLICATION_HOME_DIR$/plugins/android/lib/androidAnnotations.jar!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar://$USER_HOME$/Library/Android/sdk/platforms/android-26/android.jar!/" type="simple" />
<root url="file://$USER_HOME$/Library/Android/sdk/platforms/android-26/data/res" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite" />
</javadocPath>
<sourcePath>
<root type="composite">
<root url="file://$USER_HOME$/Library/Android/sdk/sources/android-26" type="simple" />
</root>
</sourcePath>
</roots>
<additional jdk="1.8" sdk="android-26" />
</jdk>
<jdk version="2">
<name value="Android API 23 Platform" />
<type value="Android SDK" />
<version value="java version &quot;1.8.0_152-release&quot;" />
<homePath value="$USER_HOME$/Library/Android/sdk" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar:///private/var/folders/b2/cyvk3_yx2g79yctwzx_l7lx80000gn/T/AppTranslocation/2A3A91C1-D3F4-4B90-9B20-E2C1047BDD8F/d/Android Studio 3.5.app/Contents/plugins/android/lib/androidAnnotations.jar!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar://$USER_HOME$/Library/Android/sdk/platforms/android-23/android.jar!/" type="simple" />
<root url="file://$USER_HOME$/Library/Android/sdk/platforms/android-23/data/res" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite">
<root url="http://developer.android.com/reference/" type="simple" />
</root>
</javadocPath>
<sourcePath>
<root type="composite" />
</sourcePath>
</roots>
<additional jdk="1.8" sdk="android-23" />
</jdk>
<jdk version="2">
<name value="Android API 28 Platform" />
<type value="Android SDK" />
<version value="java version &quot;1.8.0_152-release&quot;" />
<homePath value="$USER_HOME$/Library/Android/sdk" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar://$USER_HOME$/Library/Android/sdk/platforms/android-28/data/annotations.zip!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar://$USER_HOME$/Library/Android/sdk/platforms/android-28/android.jar!/" type="simple" />
<root url="file://$USER_HOME$/Library/Android/sdk/platforms/android-28/data/res" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite">
<root url="http://developer.android.com/reference/" type="simple" />
</root>
</javadocPath>
<sourcePath>
<root type="composite" />
</sourcePath>
</roots>
<additional jdk="1.8" sdk="android-28" />
</jdk>
<jdk version="2">
<name value="Kotlin SDK" />
<type value="KotlinSDK" />
<version value="1.3.30" />
<homePath value="$USER_HOME$/Library/Application Support/AndroidStudio3.6/Kotlin/kotlinc" />
<roots>
<annotationsPath>
<root type="composite" />
</annotationsPath>
<classPath>
<root type="composite" />
</classPath>
<javadocPath>
<root type="composite" />
</javadocPath>
<sourcePath>
<root type="composite" />
</sourcePath>
</roots>
<additional />
</jdk>
<jdk version="2">
<name value="Android API 29 Platform" />
<type value="Android SDK" />
<version value="java version &quot;1.8.0_152-release&quot;" />
<homePath value="$USER_HOME$/Library/Android/sdk" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar://$APPLICATION_HOME_DIR$/plugins/android/lib/androidAnnotations.jar!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar://$USER_HOME$/Library/Android/sdk/platforms/android-29/android.jar!/" type="simple" />
<root url="file://$USER_HOME$/Library/Android/sdk/platforms/android-29/data/res" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite">
<root url="http://developer.android.com/reference/" type="simple" />
</root>
</javadocPath>
<sourcePath>
<root type="composite" />
</sourcePath>
</roots>
<additional jdk="1.8" sdk="android-29" />
</jdk>
<jdk version="2">
<name value="1.8.0_161" />
<type value="JavaSDK" />
<version value="java version &quot;1.8.0_161&quot;" />
<homePath value="/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home" />
<roots>
<annotationsPath>
<root type="composite">
<root url="jar://$APPLICATION_HOME_DIR$/lib/jdkAnnotations.jar!/" type="simple" />
</root>
</annotationsPath>
<classPath>
<root type="composite">
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/charsets.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/deploy.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/cldrdata.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/dnsns.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/jaccess.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/jfxrt.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/localedata.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/nashorn.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/sunec.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/ext/zipfs.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/javaws.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jce.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jfr.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jfxswt.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/jsse.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/management-agent.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/plugin.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/resources.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre/lib/rt.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/ant-javafx.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/dt.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/javafx-mx.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/jconsole.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/packager.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/sa-jdi.jar!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/lib/tools.jar!/" type="simple" />
</root>
</classPath>
<javadocPath>
<root type="composite" />
</javadocPath>
<sourcePath>
<root type="composite">
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/src.zip!/" type="simple" />
<root url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/javafx-src.zip!/" type="simple" />
</root>
</sourcePath>
</roots>
<additional />
</jdk>
</component>
</application>
无论如何,新文件看起来像这样,现在我没有遇到我的问题(由于正文限制,我无法直接在此处发布内容)
https://pastebin.com/EdDKpZAT
但是,当我尝试在我的项目中创建新模块时,Android Studio 仍然使用我认为错误的配置和 JDK7 设置来创建它:
apply plugin: 'java-library'
apply plugin: 'kotlin'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
但是在该模块中,我可以导入对 javax 的引用

关于Android Studio : unresolved reference for java and javax imports, 但项目编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62485630/

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