‘compileDebugJavaWithJavac’在Android Studio Flamingo中出现错误

huangapple go评论68阅读模式
英文:

'compileDebugJavaWithJavac' error with Android Studio Flamingo

问题

When I updated Android Studio to Flamingo version, Gradle suggested the upgrade and I upgraded with AGP from 7.4 to 8.0. I was never able to debug after this upgrade, and as a result of my research, I could not come to a conclusion. If there is any information I have given missing for the problem, if you specify, I can make additions. I'm sharing my gradle module app codes because I think the problem stems from here.

My build.gradle(app):

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.example.packagename"
        multiDexEnabled true
        minSdkVersion 22
        targetSdkVersion 33
        versionCode 15
        versionName "1.4"
    }
    buildTypes {
        release {
            minifyEnabled true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
    namespace 'com.example.packagename'
}

Error:

Execution failed for task ':app:compileDebugJavaWithJavac'.
> superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x1db9193f) cannot access class com.sun.tools.javac.tree.TreeScanner (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.tree to unnamed module @0x1db9193f
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
.
.
.

I tried almost all the suggestions mentioned in StackOverFlow for solution but couldn't reach a solution.

<details>
<summary>英文:</summary>

When I updated Android Studio to Flamingo version, Gradle suggested the upgrade and I upgraded with AGP from 7.4 to 8.0. I was never able to debug after this upgrade, and as a result of my research, I could not come to a conclusion. If there is any information I have given missing for the problem, if you specify, I can make additions. I&#39;m sharing my gradle module app codes because I think the problem stems from here.

My build.gradle(app):

    apply plugin: &#39;com.android.application&#39;
    apply plugin: &#39;kotlin-android&#39;
    
    android {
        useLibrary &#39;org.apache.http.legacy&#39;
        compileSdkVersion 33
    
        defaultConfig {
            applicationId &quot;com.example.packagename&quot;
            multiDexEnabled true
            minSdkVersion 22
            targetSdkVersion 33
            versionCode 15
            versionName &quot;1.4&quot;
    
        }
        buildTypes {
            release {
                minifyEnabled true
    
                proguardFiles getDefaultProguardFile(&#39;proguard-android.txt&#39;), &#39;proguard-rules.pro&#39;
            }
        }
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_11
            targetCompatibility JavaVersion.VERSION_11
        }
        kotlinOptions {
            jvmTarget = &#39;11&#39;
        }
        namespace &#39;com.example.packagename&#39;
    
    }



Error:

    Execution failed for task &#39;:app:compileDebugJavaWithJavac&#39;.
    &gt; superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x1db9193f) cannot access class com.sun.tools.javac.tree.TreeScanner (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.tree to unnamed module @0x1db9193f
    * Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task &#39;:app:compileDebugJavaWithJavac&#39;.
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
    .
    .
    .



I tried almost all the suggestions mentioned in StackOverFlow for solution but couldn&#39;t reach a solution.


</details>


# 答案1
**得分**: 4

现在唯一能确保项目可构建的方法是确保使用Java 11

 1. Android Studio中转到`设置 -> 构建,执行,部署 -> 构建工具 -> Gradle`
 2. `Gradle JDK` - 确保选择了Java 11
 3. 如果这没有帮助,不要更改设置,而是尝试使用选项“使缓存无效...”,然后重新启动Android Studio,看看是否有帮助。

另外,我建议将AGP降级回7.4。我知道这不会带来所有的功能和修复,但正如你所说,关于我们可以做什么,现在有很少的信息。

另一方面,Butterknife的作者声称他将处理与AGP集成的“关键错误修复”:
[![进入图片描述][2]][2]

还要确保你已经配置了`build.gradle`文件来使用Java 11

    compileOptions {
        sourceCompatibility = &quot;11&quot;
        targetCompatibility = &quot;11&quot;
    }

<details>
<summary>英文:</summary>

For now the only way how to get your project buildable is to make sure to use Java 11.

 1. In Android Studio go to `Settings -&gt; Build, Execution, Deployment -&gt; Build Tools -&gt; Gradle`
 2. `Gradle JDK` - make sure you have selected Java 11
 3. In case it did not help, do not change the setting, rather try &quot;Invalidate Caches...&quot; with option to restart Android Studio and see if that helps.

Also I would suggest to downgrade AGP back to 7.4. I know that this does not bring all the features and fixes on board, but as you said, there are few info out there about what we can do, now.
On the other hand, author of Butterknife [claims][1] that he will manage &quot;critical bug fixes for integration with AGP&quot;:
[![enter image description here][2]][2]

Also make sure that you have configure your `build.gradle` file to use Java 11:

    compileOptions {
        sourceCompatibility = &quot;11&quot;
        targetCompatibility = &quot;11&quot;
    }


  [1]: https://github.com/JakeWharton/butterknife
  [2]: https://i.stack.imgur.com/CU1M3.png

</details>



# 答案2
**得分**: 1

I solved the problem by reverting to the old version as follows.
First of all, I downloaded and installed the Electric Eel version. (Official archive site to download old versions: [**CLICK**][1])

I then changed the content of **gradle-wrapper.properties** to:

distributionBase=GRADLE_USER_HOME
distributionUrl=https://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME


Then I set the **Gradle JDK** with the steps "**File > Build, Execution, Deploymend > Gradle**" as follows: **jbr-11** *(Jetbrains Runtime version 11.0.5...)*
I then followed these steps: "**File > Project Structure**"
And
Android Gradle Plugin Version: **7.4.2**
Gradle Version: **8.0.1**
Right now at least I'm able to compile and run my project.
Thanks to everyone who tried to help.
[1]: https://developer.android.com/studio/archive
<details>
<summary>英文:</summary>
I solved the problem by reverting to the old version as follows.
First of all, I downloaded and installed the Electric Eel version. (Official archive site to download old versions: [**CLICK**][1])
I then changed the content of **gradle-wrapper.properties** to:
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Then I set the **Gradle JDK** with the steps &quot;**File &gt; Build, Execution, Deploymend &gt; Gradle**&quot; as follows: **jbr-11** *(Jetbrains Runtime version 11.0.5...)*
I then followed these steps: &quot;**File &gt; Project Structure**&quot;
And
Android Gradle Plugin Version: **7.4.2**
Gradle Version: **8.0.1**
Right now at least I&#39;m able to compile and run my project.
Thanks to everyone who tried to help.
[1]: https://developer.android.com/studio/archive
</details>

huangapple
  • 本文由 发表于 2023年4月17日 21:13:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035561.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定