We’re building a Unity plugin library with Android Studio, for use in our Unity 5.3.5f1 project with target api 23.
Currently we have an issue trying to get the resource files to work correctly. It doesn’t seem like the Android Studio project is including the res folder in the AAR output file. If we place the res folder in the Plugins/Android folder or if we place itself as a library project, we get the following error:
C:\Users\Desktop\Unity53\Project\Temp\StagingArea\android-libraries\rlayout\res\values\values.xml:68: error: Error retrieving parent for item: No resource found that matches the given name 'Base.Widget.AppCompat.Button.Borderless'.
C:\Users\Desktop\Unity53\Project\Temp\StagingArea\android-libraries\rlayout\res\values\values.xml:74: error: Error retrieving parent for item: No resource found that matches the given name 'Base.Widget.AppCompat.Button.Small'.
If we remove the res folder and build, we get this error on runtime when the SDK is invoked:
12-24 00:43:38.725 15711-15711/? I/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: com.project.plugin.R$layout
java.lang.NoClassDefFoundError: com.project.plugin.R$layout
at com.project.plugin.header.HeaderReader$Builder.initUI(HeaderReader.java:79)
at com.project.plugin.header.HeaderReader$Builder.<init>(HeaderReader.java:73)
at com.project.plugin.Plugin$PluginBuilder.purchase(Plugin.java:1028)
at com.project.plugin.Main.requestPurchase(Main.java:529)
at com.project.plugin.Main.Bridge_requestPurchase(Main.java:700)
at com.unity3d.player.ReflectionHelper.nativeProxyInvoke(Native Method)
at com.unity3d.player.ReflectionHelper.a(Unknown Source)
at com.unity3d.player.ReflectionHelper$1.invoke(Unknown Source)
at $Proxy1.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5285)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.
Is this an issue on the Android Studio side or the Unity side? Any solutions or known fixes?
Here is the Android Studio gradle file as well:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'}
}
apply plugin: 'com.android.library'dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile 'com.loopj.android:android-async-http:1.4.9'compile 'cz.msebera.android:httpclient:4.3.6'compile 'com.google.code.gson:gson:2.6.2'compile 'org.buraktamturk:loadingview:1.0.0@aar'compile 'com.android.support:appcompat-v7:25.0.0'}
repositories {
jcenter()
flatDir {
dirs 'libs'}
}
android {
compileSdkVersion 25buildToolsVersion "25.0.0"defaultConfig {
minSdkVersion 14targetSdkVersion 22versionCode 1versionName "1.0"}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7targetCompatibility JavaVersion.VERSION_1_7}
task copyLibs(type: Copy) {
from configurations.compileinto 'libs'}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...instrumentTest.setRoot('tests')
// Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization.debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
android.libraryVariants.all { variant ->
variant.outputs.each { output ->
output.packageLibrary.exclude('libs/classes.jar')
output.packageLibrary.exclude('libs/android-support-v7-appcompat.jar')
}
}