Native Plugins and Unity 5b

Hello, I am trying to upgrade my plugins to work with Unity 5

__Unity Asset Store - The Best Assets for Game Making

Android
The way Unity collecting resources for building jar is obviously changed, so I changed plugin resources structure to fit new rules, but there is the issue with I do not know how to fix:

AndroidManifest.xml:6: error: Error: No resource found that matches the given name (at 'value' with value '@string/app_id').

But the is string app id value in the project:
in Assets/Plugins/Android/res/values/ids.xml:

<stringname="app_id">216817929098</string>

Here is example project with have compilation errors with Unity 5, and not compilation issue with older Unity versions:
https://www.dropbox.com/s/um6i7gzeu3tr3z5/TestProjectUnity5.zip?dl=0

IOS
When I try to compile the Xcode project (Xcode 6) the scripts from Assets/Plugins/IOS isn’t added to the Xcode project. I saw in the release notes that deep plugin folder support added, but nothing about that scripts from Assets/Plugins/IOS will not work any more.
Can you give my advice how should I update folders structure to make it work.

Thanks in advance.

1 Like

Hello.
I also had the same problem.
It would help us if you would the answer.

I hope Unity will notice with thread and will provide at leas some instruction of how to manage native plugins with Unity 5 or is it just issue of Unity 5b.

Bump. Having this issue in Unity 5.0.0b14. Unable to build to android because the “No resource found” error for the XML/file_paths and Integer/google_play_services_version, despite them being available.

Would appreciate a fix!

@lacost native plugins should be just fine with the new Plugin Importer. Default processor architecture is armv7a. If you experience more issues - please submit a bug report.

As for your manifest error - we are dropping support for resources in Assets/Plugins/Android/res. You should create an Android library project and move resources there, more details here: Unity - Manual: Create and use plug-ins in Android , section Android Library Projects.
This is the recommended way of doing things, though we will probably introduce a backward-compatible solution soon.

@DMTSource you should take a look at your resources as well.

1 Like

Hey @Yury-Habets , thanks for reply.

So you mean I just need to get latest Unity version and it will fix IOS issue?

Got it, thanks will need to change plugin architecture I bit but that’s okay

Cheers!

Ahh sorry I’m not sure how that works with iOS - my area is Android :eyes:
So my answer above applies to Android.

Okay, well atleast I know how to rebuild plugin architecture to work with the Unity 5 :slight_smile:

This is great news in monday!!!

Yea, almost done, Android Native 5.2 will have Unity 5 support.
But steel waiting the answer about IOS plugins compilation issue.

Hello, @Yury-Habets , I have the problem with project resources files in Unity 5.

You mentioned earlier

So, I built Android Project as Library Project


[Image Link]

AN_Social manifest file is as following:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.an_social"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
   
        <!-- File Sharing Block -->
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="APP_BUNDLE_ID.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>
        <!-- Block End -->
   
    </application>

</manifest>

As you can see, it contains FileProvider description for file sharing.
File ‘res/xml/file_paths.xml’ is in project ‘res’ folder


[Image Link]

‘res/xml/file_paths.xml’ content showed above:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="shared_images" path=""/>
</paths>

As a result Library Project was built successfully.
an_social.jar file was copied to Plugins/Android/libs folder in Unity project.


[Image Link]

In Java code I get Uri for shared file in internal storage using FileProvider class (line 26).

@SuppressLint("NewApi")
     public static Uri getImageUri(Context inContext, byte[] byteArray) {
    
         try {        
             Log.d("AndroidNative", "Creating Share URI with external storage");
             Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
        
             ByteArrayOutputStream bytes = new ByteArrayOutputStream();
             bmp.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
             String path = Images.Media.insertImage(inContext.getContentResolver(), bmp, "Screenshot", null);
             ShredUri = Uri.parse(path);
             Log.d("AndroidNative", ShredUri.toString());
             return  ShredUri;
         
         } catch (Exception ex) {        
             try {
                Log.d("AndroidNative", "Creating Share URI with local storage");
                File tempFile;
                tempFile = new File(inContext.getCacheDir(), "screen.png");
                FileOutputStream fos = new FileOutputStream(tempFile);
                fos.write(byteArray);
                fos.close();
           
                Log.d("AndroidNative", "Time to Get Uri From FileProvider");
           
                ShredUri = FileProvider.getUriForFile(SocialConf.GetLauncherActivity(),  SocialConf.GetLauncherActivity().getPackageName() +  ".fileprovider", tempFile);           
           
                return ShredUri;
           
             } catch (Exception ex2) {
                 Log.i("AndroidNative", "Get Uri from FileProvider failed! " + ex2.getMessage());
                 return Uri.parse("");
             }
         }
    }

But, unfortunatelly, I have next exception while getting image uri from FileProvider:

12-21 16:11:04.011: D/AndroidNative(25775): Creating Share URI with local storage
12-21 16:11:04.014: D/AndroidNative(25775): Time to Get Uri From FileProvider
12-21 16:11:04.016: I/AndroidNative(25775): Get Uri from FileProvider failed!
12-21 16:11:04.016: W/System.err(25775): java.lang.NullPointerException: println needs a message
12-21 16:11:04.017: W/System.err(25775): at android.util.Log.println_native(Native Method)
12-21 16:11:04.017: W/System.err(25775): at android.util.Log.d(Log.java:139)
12-21 16:11:04.017: W/System.err(25775): at com.androidnative.features.social.common.SocialGate.getImageUri(SocialGate.java:219)
12-21 16:11:04.017: W/System.err(25775): at com.androidnative.features.social.common.SocialGate.StartShareIntentMedia(SocialGate.java:54)
12-21 16:11:04.018: W/System.err(25775): at com.unity3d.player.ReflectionHelper.nativeProxyInvoke(Native Method)
12-21 16:11:04.018: W/System.err(25775): at com.unity3d.player.ReflectionHelper.a(Unknown Source)
12-21 16:11:04.018: W/System.err(25775): at com.unity3d.player.ReflectionHelper$1.invoke(Unknown Source)
12-21 16:11:04.018: W/System.err(25775): at $Proxy0.run(Native Method)
12-21 16:11:04.018: W/System.err(25775): at android.os.Handler.handleCallback(Handler.java:808)
12-21 16:11:04.018: W/System.err(25775): at android.os.Handler.dispatchMessage(Handler.java:103)
12-21 16:11:04.018: W/System.err(25775): at android.os.Looper.loop(Looper.java:193)
12-21 16:11:04.019: W/System.err(25775): at android.app.ActivityThread.main(ActivityThread.java:5292)
12-21 16:11:04.019: W/System.err(25775): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 16:11:04.019: W/System.err(25775): at java.lang.reflect.Method.invoke(Method.java:515)
12-21 16:11:04.019: W/System.err(25775): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
12-21 16:11:04.019: W/System.err(25775): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
12-21 16:11:04.020: W/System.err(25775): at dalvik.system.NativeStart.main(Native Method)

In previous versions of Unity project worked correctly.
As we know Unity 5 has new logic for collecting resources needed for build.
Could you give me any advice to fix this issue?

Thanks in advance.

The pictures in your post seem to be missing, or is it just for me? :slight_smile:

Do I understand it correctly that you created a Android Library project, compiled it into .jar, and then just dropped the .jar onto Unity project?

The documentation may be a bit unclear, but you need to drop your whole library project folder into Assets/Plugins/Android/%your_library_name%
It should contain project.properties and Android.manifest in the root, res/ and bin/ folders with compiled .jar file etc.
When building, Unity looks for subfolders in Assets/Plugins/Android/ that contain project.properties with library property set to true, and does appropriate res/ folder merge, manifest merge, .jar merge etc.

Hope that helps.

P.S. We are providing a backward compatible method to provide resources in Assets/Plugins/Android/res in the upcoming beta. It will drop a warning, but should work.