Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Native Plugins and Unity 5b

Discussion in 'Unity 5 Pre-order Beta' started by stanislav-osipov, Nov 7, 2014.

  1. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Hello, I am trying to upgrade my plugins to work with Unity 5
    https://www.assetstore.unity3d.com/en/#!/content/10825
    https://www.assetstore.unity3d.com/en/#!/content/7421

    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:

    Code (CSharp):
    1. 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:
    Code (CSharp):
    1. <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.
     
    DziDAI likes this.
  2. Penny_

    Penny_

    Joined:
    Nov 18, 2014
    Posts:
    2
    Hello.
    I also had the same problem.
    It would help us if you would the answer.
     
  3. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    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.
     
  4. DMTSource

    DMTSource

    Joined:
    Jul 11, 2013
    Posts:
    36
    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!
     
  5. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    @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: http://docs.unity3d.com/Manual/PluginsForAndroid.html , 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.
     
    stanislav-osipov likes this.
  6. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    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!
     
  7. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Ahh sorry I'm not sure how that works with iOS - my area is Android o_O
    So my answer above applies to Android.
     
  8. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Okay, well atleast I know how to rebuild plugin architecture to work with the Unity 5 :)
     
  9. DziDAI

    DziDAI

    Joined:
    Dec 6, 2012
    Posts:
    68
    This is great news in monday!!!!
     
  10. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Yea, almost done, Android Native 5.2 will have Unity 5 support.
    But steel waiting the answer about IOS plugins compilation issue.
     
  11. AlexRay

    AlexRay

    Joined:
    Jul 9, 2014
    Posts:
    993
    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:

    Code (CSharp):
    1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    2.     package="com.example.an_social"
    3.     android:versionCode="1"
    4.     android:versionName="1.0" >
    5.  
    6.     <uses-sdk
    7.         android:minSdkVersion="8"
    8.         android:targetSdkVersion="21" />
    9.  
    10.     <application
    11.         android:allowBackup="true"
    12.         android:icon="@drawable/ic_launcher"
    13.         android:label="@string/app_name"
    14.         android:theme="@style/AppTheme" >
    15.    
    16.         <!-- File Sharing Block -->
    17.         <provider
    18.             android:name="android.support.v4.content.FileProvider"
    19.             android:authorities="APP_BUNDLE_ID.fileprovider"
    20.             android:exported="false"
    21.             android:grantUriPermissions="true">
    22.             <meta-data
    23.                 android:name="android.support.FILE_PROVIDER_PATHS"
    24.                 android:resource="@xml/file_paths" />
    25.         </provider>
    26.         <!-- Block End -->
    27.    
    28.     </application>
    29.  
    30. </manifest>
    31.  
    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:
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <paths xmlns:android="http://schemas.android.com/apk/res/android">
    3.     <cache-path name="shared_images" path=""/>
    4. </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).

    Code (CSharp):
    1. @SuppressLint("NewApi")
    2.      public static Uri getImageUri(Context inContext, byte[] byteArray) {
    3.    
    4.          try {        
    5.              Log.d("AndroidNative", "Creating Share URI with external storage");
    6.              Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    7.        
    8.              ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    9.              bmp.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    10.              String path = Images.Media.insertImage(inContext.getContentResolver(), bmp, "Screenshot", null);
    11.              ShredUri = Uri.parse(path);
    12.              Log.d("AndroidNative", ShredUri.toString());
    13.              return  ShredUri;
    14.          
    15.          } catch (Exception ex) {        
    16.              try {
    17.                 Log.d("AndroidNative", "Creating Share URI with local storage");
    18.                 File tempFile;
    19.                 tempFile = new File(inContext.getCacheDir(), "screen.png");
    20.                 FileOutputStream fos = new FileOutputStream(tempFile);
    21.                 fos.write(byteArray);
    22.                 fos.close();
    23.            
    24.                 Log.d("AndroidNative", "Time to Get Uri From FileProvider");
    25.            
    26.                 ShredUri = FileProvider.getUriForFile(SocialConf.GetLauncherActivity(),  SocialConf.GetLauncherActivity().getPackageName() +  ".fileprovider", tempFile);          
    27.            
    28.                 return ShredUri;
    29.            
    30.              } catch (Exception ex2) {
    31.                  Log.i("AndroidNative", "Get Uri from FileProvider failed! " + ex2.getMessage());
    32.                  return Uri.parse("");
    33.              }
    34.          }
    35.     }
    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.
     
    Last edited: Dec 22, 2014
  12. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    The pictures in your post seem to be missing, or is it just for me? :)

    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.