Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native plugin for Android #3

Closed
cai-mobfish opened this issue Apr 9, 2020 · 9 comments · Fixed by #58
Closed

Native plugin for Android #3

cai-mobfish opened this issue Apr 9, 2020 · 9 comments · Fixed by #58

Comments

@cai-mobfish
Copy link
Contributor

Description

iOS plugin already works in the project, native methods can be called. We need the same for Android.

@cdytoby cdytoby added the help wanted Extra attention is needed label Apr 29, 2020
@cai-mobfish
Copy link
Contributor Author

I did a quick test on this, and there are multiple issues with gradle build.

  • AndroidManifest merge error
  • Theme resource not found

These are probably due to AndroidManifest or resource files in built aar file. Or I built aar file from Cardboard SDK wrong.

@cai-mobfish
Copy link
Contributor Author

cai-mobfish commented May 15, 2020

My Result so far:

For Build from IntelliJ IDEA/Android Studio (all in sdk folder):

  • Change the style to following so that the build from unity won't popup resource merge issue:
   <style name="AppTheme" parent="android:Theme.Light">
        <item name="android:windowContentOverlay">@null</item>
    </style>
  • Change the rest of the resources accordingly, so that they don't reference these style values.
  • Remove the AppName and AppTheme properties in AndroidManifest, so that unity won't popup manifest merge issue.
  • In gradle task panel, click sdk/Tasks/build/assemble instead of build, assemble is the only one without critical exception.

This maybe correct or incorrect, because I can't confirm if it works in Unity.

For usage in Unity:

  • DLLName is cardboard_api or libcardboard_api
  • Crash on start, there is no log. After logged a lot, it seems crash in CardboardQrCode_getSavedDeviceParams
  • Cardboard_initializeAndroid is not called. But need to find a way to call it, this includes get a JavaVM pointer and a context.

This is the aar file I built.
CardboardAndroid.zip

@cai-mobfish
Copy link
Contributor Author

cai-mobfish commented May 29, 2020

After thousands of errors and exceptions, finally get it to a minor working state:

sdk-debug.zip

This is the aar plugin, except of removing user-feature tag for openglES2.0, nothing is changed. This is built based on Cardboard Plugin 1.1.0, which has changed a lot since initial version.

Following things must be done in Unity, I don't like it but this is the current states.

  • Custom gradle files must be created, and following packages must be added to dependencies:
    • implementation 'com.android.support:appcompat-v7:28.0.0' (This is for the activity itself)
    • implementation 'com.android.support:support-compat:28.0.0' (Ask for permission method is in a class within this package)
    • implementation 'com.google.android.gms:play-services-vision:15.0.2' (QR Code process class is in this package)
    • implementation 'com.google.protobuf:protobuf-lite:3.0.0' (For decoding the qr code url)
  • Target SDK MUST be 9.0 instead of 10 which is already released. Google uses getExternalStorageDirectory to access file storage and store the cardboard profile, but something is changed in Android 10 and external storage can not be easily accessed. (I'm not sure if this is true). Anyway, otherwise I'll get folder or file access denied when scan the qr code.
  • Write Permission should be "External(SDCard)" in project setting.

This storage situation is terrible in my opinion, because sooner or later Google Play will say all apps must target Android 10, and this has to be changed.

https://developer.android.com/training/data-storage#scoped-storage

@hawkwood
Copy link

How much of these issues are related to using their library for QR code scanning, and could that be alleviated by switching to use https://github.com/micjahn/ZXing.Net ?

@cai-mobfish
Copy link
Contributor Author

@hawkwood

This shouldn't be much issue using play service for qr code scanning, there are other reasons that I want to prevent using external libraries.

There are a lot of third party assets/plugins using Google Support packages, like facebook SDK and firebase SDK, and they use actual aar files in Plugins folder instead of using dependency in gradle. I had a lot of troubles trying to get them work together, even with the "Jar Resolver" plugin. If this SDK requires additional google support librarys it will only add pain. But there aren't much I can do for now.

About qr code scanning, these parts are used in android library, so even I switch to ZXing, it would be java implementation of ZXing instead of ZXing.Net. It is possible but I don't think I'll do that for now.

@cai-mobfish
Copy link
Contributor Author

A fork is created from Google Cardboard.

https://github.com/mobfishgmbh/cardboard

I need proper way to track that much changes from source code.

@cdytoby cdytoby removed the help wanted Extra attention is needed label Jun 28, 2020
@cdytoby
Copy link
Collaborator

cdytoby commented Jun 28, 2020

  • Merged into public-dev.
  • Document Updated.
  • A fork is created from Google Cardboard.
  • QR Code scan issue is fixed for android.
  • getExternalStorageDirectory issue is resolved.
  • Target SDK is API 29 and External(SDCard) write permission is no longer needed.
  • Cardboard Profile is now NOT shareable, each app will have its own cardboard profile data.

@cai-mobfish cai-mobfish linked a pull request Jul 5, 2020 that will close this issue
@cai-mobfish cai-mobfish added this to the ReleaseCandidate 0.8 milestone Jul 5, 2020
@cai-mobfish
Copy link
Contributor Author

Merged to master and released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants