Search code examples
androidunity-game-engineandroid-manifestgoogle-cardboardgoogle-vr

How to compile a APK containing the Google Cardboard driver for Android 4.1 (SDK 16)


Both the current official Google Cardboard app and the older versions of the Google Cardboard drivers for Unity work for Android 4.1 and above.

However the current version of Google Cardboard for Unity library is set for Android 4.4 and above. I have tried to change the settings from 4.4 to 4.1 searching all the strings like: <uses-sdk android:minSdkVersion="19" to change it to <uses-sdk android:minSdkVersion="16".

The player settings has been change to 16 too.

Unfortunately I get the following error when compiling:

Error: [Temp/StagingArea/AndroidManifest-main.xml:14, /Users/ch/workspaces/unity_workspace/educainventions/Temp/StagingArea/android-libraries/unitygvractivity/AndroidManifest.xml:2] 
Main manifest has <uses-sdk android:minSdkVersion='16'> but library uses minSdkVersion='19'

And that's right: /Temp/StagingArea/android-libraries/unitygvractivity/AndroidManifest.xml is set to minSdkVersion='19'

I have changed that file to 16 too, but when compiling it changes to 19, and the same error occurs.

What creates that file to change it from 19 to 16? I think a solution could be to generate the Android code, then compile it with Android Studio. However doing it every time would be very slow so a continuos waste of time...


Solution

  • The generated file with 19 instead 16 is created at: Temp/StagingArea/android-libraries/unitygvractivity/AndroidM‌​anifest.xml. I have realised that we can find a file with the same name of that folder, unitygvractivity.aar, within Assets/Plugins/Android/. Searching on Google I have found that we can decompress that file. I decompress it with The Unarchiver in OSX. According to this answer, we could also execute:

    unzip unitygvractivity.aar -d unitygvractivity
    

    Once unziped, we can find AndroidM‌​anifest.xml within the extracted folder unitygvractivity. We change 19 by 16 in that file, and we compress it back to the aar format. According to the same answer we can execute:

    jar cvf unitygvractivity.aar -C unitygvractivity/ .
    

    Finally we change the original unitygvractivity.aar file by the new one we just created. It will compile.

    So the next question is: if it has worked in Android 4.1, why Google set it for 4.4 and above? Maybe a part of the library I did not use need 4.4?


    UPDATE: Answer of Google (https://github.com/googlevr/gvr-unity-sdk/issues/439):

    We uses some level-19 APIs in our sdk so it is not guaranteed to work with pre-19 target. You should set 19 as your minimal target for cardboard