When integrating Android plug-ins in the Unity project, a plug-in cannot be used. Check Logcat for an error NoClassDefFoundError:Failed resolution of:Landroid/arch/lifecycle$Event。
Problem recurrence
Integration in Unity AndroidUtilCode
Plug in is used to control Android brightness, volume and other functions in Unity. After integration, an error is reported after calling relevant methods. The error content is:
NoClassDefFoundError:Failed resolution of:Landroid/arch/lifecycle$Event
It seems that the lifecycle dependency is missing.
solve the problem
When Unity packs the apk package, it will not actively include plug-in dependencies that are not in the Plugins folder. Lifecycle is not a native plug-in, and it is integrated as an extension in support library 26.1.0
And subsequent libraries.
Why don't Android native development partners report errors? Because the package management tools they use (maven, etc.) automatically pull down these dependencies, and Unity does not. In order for the Android plug-in in Unity to use Lifecycle, we need to put the aar or jar package of Lifecycle under the Unity plug-in directory.
Unity involves two dependency files: arch-lifecycle-common
And arch-lifecycle-runtime
(See the download link at the end of the article).
After downloading, place them in the following directory:
Assets/Plugins/Android
Then repackage and solve the problem.
File download
The 1.0.0 version file used by this blog is provided here. Please download other versions yourself.
#Baidu online disk second transmission code a6624c325dd150cdd39dd94d5877723f#a6624c325dd150cdd39dd94d5877723f#12366#arch-lifecycle-common-[azimiao.com]-1.0.0.jar 266009cd71ff12d1370c3622c436789a#266009cd71ff12d1370c3622c436789a#6460#arch-lifecycle-runtime-[azimiao.com]-1.0.0.jar
See Baidu online disk second transmission principle and use method How to use Baidu netdisk second transmission link and its implementation principle 。