Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Android Native App Crash with Embeddinator generated AAR. #757

Open
amitkhoth opened this issue Feb 25, 2020 · 2 comments
Open

Android Native App Crash with Embeddinator generated AAR. #757

amitkhoth opened this issue Feb 25, 2020 · 2 comments
Milestone

Comments

@amitkhoth
Copy link

amitkhoth commented Feb 25, 2020

Steps to Reproduce

Tool used - Visual Studio for mac

  1. create android class library and multiPlatform portable class library in visual studio for mac

  2. create AAR file from this android library using command
    mono '${SolutionDir}/packages/Embeddinator-4000.0.4.0/tools/Embeddinator-4000.exe'
    '${TargetPath}' --gen=Java --platform=Android --outdir='${SolutionDir}/androidoutput' -c

  3. use this AAR file in Android Native Application

  4. This AAR file is creating a fragment using Content Page.

     [Export("getPageFragment")]
     public Android.Support.V4.App.Fragment GetPageFragment(Context context)
     {
         if (!Forms.IsInitialized) {
             Forms.Init(context, null);
         }
         return new FormPage().CreateSupportFragment(context);
     }
    

    This fragment is launched from Native APP.

    public class FormPage : ContentPage
    {
    public FormPage()
    {
    var button = new Button
    {
    Text = "Click Me Plugin2!",
    VerticalOptions = LayoutOptions.CenterAndExpand,
    HorizontalOptions = LayoutOptions.CenterAndExpand,
    };

         int clicked = 0;
         button.Clicked += (s, e) => button.Text = "Clicked:Plugin2 " + clicked++;
    
         Content = button;
     }
    

    }

Expected Behavior

Native Android App should launch the xamain.form Page.

Actual Behavior

App is crashed when getPageFragment is called from Native App.
Application is crashed when fragment is created.

Environment

=== Visual Studio Professional 2019 for Mac ===

Version 8.4.2 (build 59)
Installation UUID: 87b89047-dfac-45f2-bef1-c1b10426adaa
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 5.16.1.25 (issue-7441-d16-3-vsmac / 881172e73)

	Package version: 606000155

=== Mono Framework MDK ===

Runtime:
	Mono 6.6.0.155 (2019-08/296a9afdb24) (64-bit)
	Package version: 606000155

=== Roslyn (Language Service) ===

3.4.0-beta4-19562-05+ff930dec4565e2bc424ad3bf3e22ecb20542c87d

=== NuGet ===

Version: 5.3.0.6192

=== Xamarin Designer ===

Version: 16.4.0.478
Hash: 95f0ab363
Branch: remotes/origin/d16-4
Build date: 2020-01-08 23:59:46 UTC

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.101/Sdks
SDK Versions:
	3.1.101
	3.0.101
	3.0.100
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.6.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	3.1.1
	3.0.1
	3.0.0
	2.1.15
	2.1.14
	2.1.13

=== Xamarin.Profiler ===

Version: 1.6.12.29
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 10.1.3.7 (Visual Studio Professional)
Commit: xamarin-android/d16-4/d66aed0
Android SDK: /Users/AmitKhoth/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		5.0 (API level 21)
		7.0 (API level 24)
		7.1 (API level 25)
		8.0 (API level 26)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.5
SDK Build Tools Version: 29.0.2

Build Information: 
Mono: fd9f379
Java.Interop: xamarin/java.interop/d16-4@c4e569f
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.28.0@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/AmitKhoth/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
1.8.0-9
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.4.0.9
Hash: 3f7256f
Branch: remotes/origin/d16-4
Build date: 2020-01-14 22:19:04 UTC

=== Android Device Manager ===

Version: 16.4.0.30
Hash: f9172e2
Branch: remotes/origin/d16-4
Build date: 2020-01-14 22:19:24 UTC

=== Apple Developer Tools ===

Xcode 11.3 (15712)
Build 11C29

=== Xamarin.Mac ===

Version: 6.10.0.17 (Visual Studio Professional)
Hash: 5f802ef53
Branch: xcode11.3
Build date: 2020-01-07 11:53:06-0500

=== Xamarin.iOS ===

Version: 13.10.0.17 (Visual Studio Professional)
Hash: 5f802ef53
Branch: xcode11.3
Build date: 2020-01-07 11:53:06-0500

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 804020059
Git revision: eb6fcdd83a227678e487aa733df3c8745f54fafc
Build date: 2020-01-17 12:12:02+00
Build branch: release-8.4
Xamarin extensions: ec32c90978c94f03d72f507b01f5aee70952ce87

=== Operating System ===

Mac OS X 10.14.6
Darwin 18.7.0 Darwin Kernel Version 18.7.0
    Sun Dec  1 18:59:03 PST 2019
    root:xnu-4903.278.19~1/RELEASE_X86_64 x86_64

Build Logs

Java.Lang.ClassNotFoundException: md5b60ffeb829f638581ab2bb9b1a7f4f3f.PageRenderer ---> Java.Lang.NoClassDefFoundError: Failed resolution of: Lmd5b60ffeb829f638581ab2bb9b1a7f4f3f/VisualElementRenderer_1; ---> Java.Lang.ClassNotFoundException: md5b60ffeb829f638581ab2bb9b1a7f4f3f.VisualElementRenderer_1 ---> Java.Lang.NoClassDefFoundError: Failed resolution of: Lcom/xamarin/forms/platform/android/FormsViewGroup; ---> Java.Lang.ClassNotFoundException: Didn't find class "com.xamarin.forms.platform.android.FormsViewGroup" on path: DexPathList[[zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/base.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/lib/arm64, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/base.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]

02-19 17:33:29.332 3514 3514 E mono : --- End of inner exception stack trace ---
02-19 17:33:29.332 3514 3514 E mono : --- End of inner exception stack trace ---
02-19 17:33:29.332 3514 3514 E mono : --- End of inner exception stack trace ---
02-19 17:33:29.332 3514 3514 E mono : --- End of inner exception stack trace ---
02-19 17:33:29.332 3514 3514 E mono : at Java.Interop.JniEnvironment+Types.FindClass (System.String classname) [0x00114] in :0
02-19 17:33:29.332 3514 3514 E mono : at Java.Interop.JniType..ctor (System.String classname) [0x00006] in :0
02-19 17:33:29.332 3514 3514 E mono : at Java.Interop.JniPeerMembers+JniInstanceMethods..ctor (System.Type declaringType) [0x00064] in :0
02-19 17:33:29.332 3514 3514 E mono : at Java.Interop.JniPeerMembers+JniInstanceMethods.GetConstructorsForType (System.Type declaringType) [0x0002c] in :0
02-19 17:33:29.332 3514 3514 E mono : at Java.Interop.JniP
02-19 17:33:29.334 3514 3514 E mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Java.Lang.ClassNotFoundException: md5b60ffeb829f638581ab2bb9b1a7f4f3f.PageRenderer ---> Java.Lang.NoClassDefFoundError: Failed resolution of: Lmd5b60ffeb829f638581ab2bb9b1a7f4f3f/VisualElementRenderer_1; ---> Java.Lang.ClassNotFoundException: md5b60ffeb829f638581ab2bb9b1a7f4f3f.VisualElementRenderer_1 ---> Java.Lang.NoClassDefFoundError: Failed resolution of: Lcom/xamarin/forms/platform/android/FormsViewGroup; ---> Java.Lang.ClassNotFoundException: Didn't find class "com.xamarin.forms.platform.android.FormsViewGroup" on path: DexPathList[[zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/base.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/lib/arm64, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/base.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.example.hellowshareduijava-KWYYOz-8C3bQ6goXjdG0_w==/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
02-19 17:33:29.334 3514 3514 E mono-rt : --- End of inner exception stack trace ---
02-19 17:33:29.334 3514 3514 E mono-rt : --- End of inner exception stack trace ---
02-19 17:33:29.334 3514 3514 E mono-rt : --- End of inner exception stack trace ---

-->

Example Project (If Possible)

public class FormPage : ContentPage
{
public FormPage()
{
var button = new Button
{
Text = "Click Me Plugin2!",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};

        int clicked = 0;
        button.Clicked += (s, e) => button.Text = "Clicked:Plugin2 " + clicked++;

        Content = button;
    }
}

//////////helper class//////////////
[Register("plugin.droid.Helper")]
public class Helper : Java.Lang.Object
{
public Helper() : base()
{
}

    public Helper(IntPtr handle, JniHandleOwnership transfer)
        : base(handle, transfer)
    {

    }

    [Export("getPageFragment")]
    public Android.Support.V4.App.Fragment GetPageFragment(Context context)
    {
        if (!Forms.IsInitialized) {
            Forms.Init(context, null);
        }
        return new FormPage().CreateSupportFragment(context);
    }
}

Now use this GetPageFragment API from Android Native APPl
in MainActivity.java
Helper helpers = new Helper();
Fragment frag = helpers.getPageFragment(MainActivity.this);
Application is crashed when fragment is created.

@chamons chamons added this to the Future milestone Feb 25, 2020
@amitkhoth
Copy link
Author

amitkhoth commented Feb 26, 2020

@chamons
There is a workaround for this.
Add FormViewGroup.jar in android native Project after that it can launch xamarin.form page successfully.
can you explain why Embeddinator is not adding support for this?

@chamons
Copy link
Contributor

chamons commented Feb 26, 2020

As I noted in another issue recently:

There currently is not active development by members of the Xamarin team, but we are triaging incoming issues and assisting where it makes sense.

As a community project, the hope is that people will be able to build upon it to bundle C# libraries in native libraries....

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

No branches or pull requests

2 participants