0

I am trying to create my own Annotation processor in Android Studio project.

I've created another module for that in Android Studio.

I am able to compile the project. I can't just use autocomplete and other stuff. IDE treat all the references as unresolved references error in that case

enter image description here

How can I resolve this issue?

WHAT IS IMPORTANT

When I created new libary module "autoadapter-process" by default Android Studio created it with this implementation in build.gradle for this module:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

To be able to compile the project I replaced it to:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

Below is my JDK setup in Project Structure (Android Studio): enter image description here

Below is my project structure:

enter image description here

And here is my Gradle configuration for autoadapter-processor module:

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"
}

This https://stackoverflow.com/a/61180376/104891 problem is not similiar to mine, as it is IntelliJ IDEA specifc. It is not Android Studio specific.

K.Os
  • 5,123
  • 8
  • 40
  • 95

1 Answers1

2

It seems, that Android Studio cache some previous settings imported for the new Android Studio version. I was doing it pretty much for long time when updating probably from versions 3.1 -> 3.2 -> 3.4 -> ... -> 4.0

So the old JDK version seemed to be cached inside jdk.table.xml file

You can find this file inside whenever your Android Studio options folder is located (in my case it was User/Library/Preferences/AndroidStudio4.0/options)

You can either delete it and let it be created again with proper versions (which worked for me and is the solution for my problem: https://stackoverflow.com/a/38067170/5434346

Or you can try to modify it (I did not tried that): https://stackoverflow.com/a/41531367/5434346

What is strange it did not contained any JDK 1.7 references:

<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>

Anyway, the new file looks like this and now I don't experience my issue (I was not able to post the content straight here due to body limit) https://pastebin.com/EdDKpZAT

However, when i try to create new module inside my project Android Studio still create the it with I think wrong configuration and JDK7 setup:

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"

But inside that module I am able to import my references to javax

K.Os
  • 5,123
  • 8
  • 40
  • 95