Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Androidx library support

Discussion in 'Android' started by Culzean, Jul 9, 2019.

  1. Culzean

    Culzean

    Joined:
    Jan 25, 2014
    Posts:
    47
    The latest build tools for Android have not replaced many support libraries with androidx versions.
    See https://developer.android.com/jetpack/androidx/migrate

    These should be used in place of older android support libraries. However some changes to the gradle.properties file is required to integrate these libraries. The following lines need to be added.

    android.enableJetifier=true
    android.useAndroidX=true

    The only way I can see to include these lines is to export the project and edit the build that way. Does anyone know of a way to edit the gradle.properties file through unity and create from the editor? And failing this, is this something Unity will be working on soon? Changing to Androidx libraries will be very urgent soon.

    Cheer.
     
  2. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    759
    Use this callback interface to update the gradle.properties file instead of exporting to android project, which is obviously very tedious. Hope it helps!
     
  3. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    759
    Have a look over here to automate patching of gradle.properties file. You can comment the first method and use
    EnableJetifierIfRequired method alone for your scenario.

    Thanks,
    VB Team
     
    xVergilx likes this.
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    1,875
    Even with jetifier options added to the gradle.properties, build fails with:
    Code (csharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:\Program Files\Unity\Hub\Editor\2018.4.5f1\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2018.4.5f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
    3.  
    4. stderr[
    5.  
    6. FAILURE: Build failed with an exception.
    7.  
    8. * What went wrong:
    9. Execution failed for task ':transformClassesWithMultidexlistForRelease'.
    10. > com.android.build.api.transform.TransformException: Error while generating the main dex list.
    11.  
    12. * Try:
    13. 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.
    14.  
    15. * Get more help at https://help.gradle.org
    16.  
    17. BUILD FAILED in 1m 29s
    18. ]
    19. stdout[
    20. > Task :checkReleaseClasspath UP-TO-DATE
    21. > Task :preBuild UP-TO-DATE
    22. > Task :Firebase:preBuild UP-TO-DATE
    23. > Task :Firebase:preReleaseBuild UP-TO-DATE
    24. > Task :Firebase:checkReleaseManifest
    25. > Task :Firebase:processReleaseManifest
    26. > Task :IronSource:preBuild UP-TO-DATE
    27. > Task :IronSource:preReleaseBuild UP-TO-DATE
    28. > Task :IronSource:checkReleaseManifest
    29. > Task :IronSource:processReleaseManifest
    30. > Task :preReleaseBuild UP-TO-DATE
    31. > Task :Firebase:compileReleaseAidl NO-SOURCE
    32. > Task :IronSource:compileReleaseAidl NO-SOURCE
    33. > Task :compileReleaseAidl NO-SOURCE
    34. > Task :Firebase:packageReleaseRenderscript NO-SOURCE
    35. > Task :IronSource:packageReleaseRenderscript NO-SOURCE
    36. > Task :checkReleaseManifest UP-TO-DATE
    37. > Task :generateReleaseBuildConfig UP-TO-DATE
    38. > Task :compileReleaseRenderscript UP-TO-DATE
    39. > Task :prepareLintJar UP-TO-DATE
    40. > Task :mainApkListPersistenceRelease UP-TO-DATE
    41. > Task :generateReleaseResValues UP-TO-DATE
    42. > Task :generateReleaseResources UP-TO-DATE
    43. > Task :Firebase:compileReleaseRenderscript
    44. > Task :Firebase:generateReleaseResValues
    45. > Task :Firebase:generateReleaseResources
    46. > Task :Firebase:packageReleaseResources
    47. > Task :IronSource:compileReleaseRenderscript
    48. > Task :IronSource:generateReleaseResValues
    49. > Task :IronSource:generateReleaseResources
    50. > Task :IronSource:packageReleaseResources
    51. > Task :mergeReleaseResources UP-TO-DATE
    52. > Task :createReleaseCompatibleScreenManifests UP-TO-DATE
    53. > Task :processReleaseManifest
    54. > Task :splitsDiscoveryTaskRelease UP-TO-DATE
    55. > Task :Firebase:generateReleaseRFile
    56. > Task :IronSource:generateReleaseRFile
    57. > Task :processReleaseResources
    58. > Task :generateReleaseSources
    59. > Task :Firebase:generateReleaseBuildConfig
    60. > Task :Firebase:prepareLintJar UP-TO-DATE
    61. > Task :Firebase:generateReleaseSources
    62. > Task :Firebase:javaPreCompileRelease
    63. > Task :Firebase:compileReleaseJavaWithJavac
    64. > Task :Firebase:processReleaseJavaRes NO-SOURCE
    65. > Task :Firebase:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease
    66. > Task :IronSource:generateReleaseBuildConfig
    67. > Task :IronSource:prepareLintJar UP-TO-DATE
    68. > Task :IronSource:generateReleaseSources
    69. > Task :IronSource:javaPreCompileRelease
    70. > Task :IronSource:compileReleaseJavaWithJavac
    71. > Task :IronSource:processReleaseJavaRes NO-SOURCE
    72. > Task :IronSource:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease
    73. > Task :javaPreCompileRelease UP-TO-DATE
    74. > Task :compileReleaseJavaWithJavac UP-TO-DATE
    75. > Task :compileReleaseNdk NO-SOURCE
    76. > Task :compileReleaseSources UP-TO-DATE
    77. > Task :lintVitalRelease
    78. > Task :mergeReleaseShaders UP-TO-DATE
    79. > Task :compileReleaseShaders UP-TO-DATE
    80. > Task :generateReleaseAssets UP-TO-DATE
    81. > Task :Firebase:mergeReleaseShaders
    82. > Task :Firebase:compileReleaseShaders
    83. > Task :Firebase:generateReleaseAssets
    84. > Task :Firebase:packageReleaseAssets
    85. > Task :IronSource:mergeReleaseShaders
    86. > Task :IronSource:compileReleaseShaders
    87. > Task :IronSource:generateReleaseAssets
    88. > Task :IronSource:packageReleaseAssets
    89. > Task :mergeReleaseAssets
    90. > Task :transformClassesWithDexBuilderForRelease UP-TO-DATE
    91. > Task :transformClassesWithMultidexlistForRelease FAILED
    92.  
    93. Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
    94. Use '--warning-mode all' to show the individual deprecation warnings.
    95. See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
    96. 49 actionable tasks: 31 executed, 18 up-to-date
    97. ]
    98. exit code: 1
    99. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    100. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    101. UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    102. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    103. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    104. Rethrow as GradleInvokationException: Gradle build failed
    105. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    106. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    107. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <62f761e6ab1445a38cdcb4ac36512695>:0)
    108.  
    Is there something else that should be added? I've tried both patching and non-patching gradle template via play services resolver, w/o any luck so far. It generates same error.
     
  5. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    759
    can you give a try with gradlew build --stacktrace or --scan in Temp/gradleOut folder once and pass me the results. The data you shared above doesn't seem to have much info.
     
    xVergilx likes this.
  6. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    1,875
    Do I need to export project for that one? I was building from Unity.

    Edit: Okay, I think it should work with full stack trace enabled from the Player settings. Need to try that.
     
    Last edited: Aug 5, 2019
  7. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    1,875
    Here's a stacktrace:
    Code (CSharp):
    1. > Task :transformClassesWithMultidexlistForRelease FAILED
    2.  
    3. FAILURE: Build failed with an exception.
    4.  
    5. * What went wrong:
    6. Execution failed for task ':transformClassesWithMultidexlistForRelease'.
    7. > com.android.build.api.transform.TransformException: Error while generating the main dex list.
    8.  
    9. * Try:
    10. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    11.  
    12. * Exception is:
    13. org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':transformClassesWithMultidexlistForRelease'.
    14.         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:95)
    15.         at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:91)
    16.         at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
    17.         at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:119)
    18.         at org.gradle.api.internal.tasks.execution.ResolvePreviousStateExecuter.execute(ResolvePreviousStateExecuter.java:43)
    19.         at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:93)
    20.         at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:45)
    21.         at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:94)
    22.         at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:56)
    23.         at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:55)
    24.         at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    25.         at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:67)
    26.         at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    27.         at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
    28.         at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:315)
    29.         at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:305)
    30.         at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    31.         at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:101)
    32.         at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    33.         at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
    34.         at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
    35.         at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
    36.         at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
    37.         at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
    38.         at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
    39.         at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
    40.         at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
    41.         at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
    42.         at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
    43.         at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
    44.         at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    45.         at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    46.         at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    47. Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: Error while generating the main dex list.
    48.         at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    49.         at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    50.         at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:230)
    51.         at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    52.         at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:47)
    53.         at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:41)
    54.         at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
    55.         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.run(ExecuteActionsTaskExecuter.java:284)        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    56.         at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    57.         at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    58.         at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    59.         at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:273)
    60.         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:258)
    61.         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:67)
    62.         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:145)
    63.         at org.gradle.internal.execution.impl.steps.ExecuteStep.execute(ExecuteStep.java:49)
    64.         at org.gradle.internal.execution.impl.steps.CancelExecutionStep.execute(CancelExecutionStep.java:34)
    65.         at org.gradle.internal.execution.impl.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:69)
    66.         at org.gradle.internal.execution.impl.steps.TimeoutStep.execute(TimeoutStep.java:49)
    67.         at org.gradle.internal.execution.impl.steps.CatchExceptionStep.execute(CatchExceptionStep.java:33)
    68.         at org.gradle.internal.execution.impl.steps.CreateOutputsStep.execute(CreateOutputsStep.java:50)
    69.         at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:43)
    70.         at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:29)
    71.         at org.gradle.internal.execution.impl.steps.CacheStep.executeWithoutCache(CacheStep.java:134)
    72.         at org.gradle.internal.execution.impl.steps.CacheStep.lambda$execute$3(CacheStep.java:83)
    73.         at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:82)
    74.         at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:36)
    75.         at org.gradle.internal.execution.impl.steps.PrepareCachingStep.execute(PrepareCachingStep.java:33)
    76.         at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:38)
    77.         at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:23)
    78.         at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
    79.         at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
    80.         at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:52)
    81.         at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:36)
    82.         at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:34)
    83.         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:91)
    84.         ... 32 more
    85. Caused by: com.android.build.api.transform.TransformException: Error while generating the main dex list.
    86.         at com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:144)
    87.         at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:239)
    88.         at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:235)
    89.         at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    90.         ... 68 more
    91. Caused by: com.android.builder.multidex.D8MainDexList$MainDexListException: com.android.tools.r8.errors.CompilationError: Program type already present: com.facebook.AccessTokenTracker$1
    92.         at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:87)
    93.         at com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:131)
    94.         ... 71 more
    95. Caused by: com.android.tools.r8.errors.CompilationError: Program type already present: com.facebook.AccessTokenTracker$1        at com.android.tools.r8.utils.ProgramClassCollection.resolveClassConflictImpl(ProgramClassCollection.java:64)
    96.         at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:25)
    97.         at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:24)
    98.         at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:124)
    99.         at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:123)
    100.         at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:86)
    101.         at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:40)
    102.         at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:110)
    103.         at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:83)
    104.         ... 72 more
    105.  
    106.  
    107. * Get more help at https://help.gradle.org
    108.  
    109. Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
    110. Use '--warning-mode all' to show the individual deprecation warnings.
    111. See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
    112.  
    113. BUILD FAILED in 19s
    114. 49 actionable tasks: 3 executed, 46 up-to-date
     
  8. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    1,875
    @Voxel-Busters Okay, I've seems to found out what's causing this, and its unrelated to the AndroidX (well kinda related).

    Play Services Resolver somehow extracted duplicates of the dependencies from the Facebook SDK, causing the error above. Looks like I need to cleanup facebook imported files.

    --stacktrace advice was extremely useful! Thank you!
     
  9. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    759
    Yes, looks so from the log.

    Anyways, glad you sorted out the issue. Good luck!
     
    xVergilx likes this.