googlesamples / unity-jar-resolver

Unity plugin which resolves Android & iOS dependencies and performs version management
Other
1.25k stars 343 forks source link

[Question] "annotationProcessor"/"kapt" when using Android Room Database #450

Closed dhassault closed 3 years ago

dhassault commented 3 years ago

I'm creating a Android library aar to be used in Unity3d. And in my library, I'm using Room. Once I imported my aar into Unity3D, I'm using External Dependency Manager to download all the dependencies.

My build.gradle looks like that:

dependencies {
    def room_version = "2.3.0"

    implementation("androidx.room:room-runtime:$room_version")
    annotationProcessor "androidx.room:room-compiler:$room_version"
    kapt("androidx.room:room-compiler:$room_version")

}

And when I build my game on Unity3D, I get the error:

CommandInvokationFailure: Gradle build failed. 
/home/me/Unity/Hub/Editor/2021.1.12f1/Editor/Data/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/home/me/Unity/Hub/Editor/2021.1.12f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-5.6.4.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "bundleRelease"

stderr[
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':unityLibrary:javaPreCompileRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
       - androidx.room.room-compiler-2.3.0.jar (androidx.room.room-compiler-2.3.0.jar)
     Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
     See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
]
stdout[

> Configure project :launcher
WARNING: The option 'android.enableR8' is deprecated and should not be used anymore.
It will be removed in a future version of the Android Gradle plugin, and will no longer allow you to disable R8.

> Task :unityLibrary:preBuild UP-TO-DATE
> Task :unityLibrary:preReleaseBuild UP-TO-DATE
> Task :launcher:preBuild UP-TO-DATE
> Task :launcher:preReleaseBuild UP-TO-DATE
> Task :launcher:generateReleaseResValues UP-TO-DATE
> Task :unityLibrary:packageReleaseRenderscript NO-SOURCE
> Task :launcher:mainApkListPersistenceRelease UP-TO-DATE
> Task :unityLibrary:compileReleaseRenderscript NO-SOURCE
> Task :launcher:compileReleaseRenderscript NO-SOURCE
> Task :unityLibrary:generateReleaseResValues UP-TO-DATE
> Task :launcher:generateReleaseResources UP-TO-DATE
> Task :launcher:createReleaseCompatibleScreenManifests UP-TO-DATE
> Task :launcher:extractDeepLinksRelease UP-TO-DATE
> Task :unityLibrary:generateReleaseResources UP-TO-DATE
> Task :unityLibrary:packageReleaseResources UP-TO-DATE
> Task :unityLibrary:extractDeepLinksRelease UP-TO-DATE
> Task :unityLibrary:compileReleaseLibraryResources UP-TO-DATE
> Task :unityLibrary:compileReleaseAidl NO-SOURCE
> Task :unityLibrary:generateReleaseBuildConfig UP-TO-DATE
> Task :unityLibrary:parseReleaseLocalResources UP-TO-DATE
> Task :unityLibrary:mergeReleaseShaders
> Task :unityLibrary:processReleaseManifest
> Task :unityLibrary:generateReleaseRFile UP-TO-DATE
> Task :unityLibrary:compileReleaseShaders
> Task :unityLibrary:generateReleaseAssets
> Task :unityLibrary:packageReleaseAssets
> Task :unityLibrary:javaPreCompileRelease FAILED
> Task :launcher:mergeReleaseResources
17 actionable tasks: 6 executed, 11 up-to-date
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <1eaf4a8e7f364ff486d2470048a27112>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:337)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /home/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

And specially:

...
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
       - androidx.room.room-compiler-2.3.0.jar (androidx.room.room-compiler-2.3.0.jar)
...

Is there a way to solve this?

google-oss-bot commented 3 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

paulinon commented 3 years ago

Hi @dhassault,

In order to identify what's causing this behavior, could you provide a minimal, reproducible example of your implementation?

google-oss-bot commented 3 years ago

Hey @dhassault. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

dhassault commented 3 years ago

Thank you @paulinon for your help! This issue was not related to unity-jar-resolver but a mix of my misunderstanding and versioning. I could add additional commands in the launcher template gradle. This solved some of my issues. Then I had an problem with the gradle version in unity being too old for the version of kotlin plugin (which allows to use kapt). So I downgraded the kotlin version and all other dependencies to be able to use unity's gradle. But at the end, one dependencies could not be downgraded enough (datastore). So I'm going to remove Room to avoid kapt("androidx.room:room-compiler:$room_version"). And this should solve my issue. Anyway thanks for the support!