Forum Xamarin.Android

Xamarin.Android Build Failing ONLY when referencing Binding Library

LeoJHarrisLeoJHarris NZMember ✭✭✭
edited March 3 in Xamarin.Android

Hi all, trying to get an android Binding Library to work. My Binding Library and consuming Xamarin.Android project both build fine but when I add the Binding Library as a reference to my consuming Xamarin.Android project I get a build failed as per below.

I'm no sure exactly what's going on here but I think there might be an issue with the Android support libraries or maybe some dimensions are missing that were not included in the .aar java files? But currently the build only fails when I reference the Binding library from the consuming Xamarin.Android project otherwise both build build fine when that reference is removed...

Compile Android version is Android 10.0 (API 29) and minimum is Android 5.0 (API 21)

2>------ Rebuild All started: Project: Test, Configuration: Debug Any CPU ------
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_card_editor_max_width (aka com.companyname.test:dimen/sqip_card_editor_max_width) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_big_card_editor_margin_sides (aka com.companyname.test:dimen/sqip_big_card_editor_margin_sides) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_big_card_editor_margin_sides (aka com.companyname.test:dimen/sqip_big_card_editor_margin_sides) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_big_card_editor_margin_top (aka com.companyname.test:dimen/sqip_big_card_editor_margin_top) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_card_editor_start_end_padding (aka com.companyname.test:dimen/sqip_card_editor_start_end_padding) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_card_editor_start_end_padding (aka com.companyname.test:dimen/sqip_card_editor_start_end_padding) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_big_card_height (aka com.companyname.test:dimen/sqip_big_card_height) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_big_card_width (aka com.companyname.test:dimen/sqip_big_card_width) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource dimen/sqip_helper_text_margin_top (aka com.companyname.test:dimen/sqip_helper_text_margin_top) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource string/sqip_helper_text_card (aka com.companyname.test:string/sqip_helper_text_card) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry.xml(2): error APT2260: resource style/sqip_Loading.Spinner (aka com.companyname.test:style/sqip_Loading.Spinner) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource dimen/sqip_card_editor_max_width (aka com.companyname.test:dimen/sqip_card_editor_max_width) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource dimen/sqip_card_editor_start_end_padding (aka com.companyname.test:dimen/sqip_card_editor_start_end_padding) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource dimen/sqip_card_editor_start_end_padding (aka com.companyname.test:dimen/sqip_card_editor_start_end_padding) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource string/sqip_credit_card_image_description (aka com.companyname.test:string/sqip_credit_card_image_description) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource dimen/sqip_big_card_height (aka com.companyname.test:dimen/sqip_big_card_height) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource dimen/sqip_big_card_horizontal_margin_end (aka com.companyname.test:dimen/sqip_big_card_horizontal_margin_end) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource dimen/sqip_big_card_width (aka com.companyname.test:dimen/sqip_big_card_width) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource dimen/sqip_helper_text_margin_top (aka com.companyname.test:dimen/sqip_helper_text_margin_top) not found.
2>C:\Users\SquareBindingsPOC\TestBinding\Test\obj\Debug\110\lp\0\jl\res\layout\sqip_activity_card_entry_horizontal_card_constraints.xml(2): error APT2260: resource string/sqip_helper_text_card (aka com.companyname.test:string/sqip_helper_text_card) not found.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

Answers

  • jezhjezh Member, Xamarin Team Xamurai
    edited March 4

    You can try to set the Linker of your android app to None,just as follows:

    For more details, you can check document: https://docs.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/?tabs=windows#configure-the-linker


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • LeoJHarrisLeoJHarris NZMember ✭✭✭
    edited March 4

    @jezh
    That error when away, I think it might have been to do with multiple aar/jar files in the binding library I initally had. That being said I ended up with another issue that I logged a ticket for on Xamarin.Android see here: https://github.com/xamarin/xamarin-android/issues/5686

    error: class drawable is already defined in class R

    For some reason there are duplicate class definitions for drawable and string in the R.java of the binding library

  • LeoJHarrisLeoJHarris NZMember ✭✭✭

    @jezh Got this sorted with re-organizing the R.text file as some things were not grouped correctly that being correct me if wrong here but I have an interface that is being marked internal?

    But when I decompile it then becomes public, so is android binding library making this internal and is there fore throwing this exception?

  • LeoJHarrisLeoJHarris NZMember ✭✭✭

    @jezh Think I need to update the Metadata.xml to resolve this issue is there a way to mark the visibility of an interface from the binding lib "transforms/Metadata.xml" I think this is what I need to do here...

  • LeoJHarrisLeoJHarris NZMember ✭✭✭
    edited March 9

    @jezh

    I have updated the Metadata.xml with some remove-nodes on these interfaces that were causing exceptions and those exceptions have gone away but have got another exception

    Java.Lang.NoClassDefFoundError: 'Failed resolution of: Lsqip/internal/SqipActivityDebouncer;'
    

    Not sure if I'm fixing issues or creating more :neutral:

  • jezhjezh Member, Xamarin Team Xamurai

    Could you please share your detailed steps with me?

  • LeoJHarrisLeoJHarris NZMember ✭✭✭
    edited March 11

    @jezh said:
    Could you please share your detailed steps with me?

    Hi @jezh I managed to get that error resolved, what it was was a missing dependency being referenced somewhere. That being said I've been struggling for last few days on another particular issue which I think is one of the last stepping stones to getting this binding lib working....

    The issue involves dagger which my binding library is using in some of the jar/aar files, so I created a binding library from the jar dagger from the native android SDK however when I built the library and ran the consuming application I got this exception:

    Java.Lang.NoClassDefFoundError: 'Failed resolution of: Ldagger/internal/Factory;'
    

    The way I got around this exception was to add Xamarin.Google.Dagger into my android application but that creates issues having 2 different versions of dagger:

    Error in obj\Debug\100\lp\5\jl\dagger-2.30.1.jar:dagger/Binds.class:
    Type dagger.Binds is defined multiple times: obj\Debug\100\lp\5\jl\dagger-2.30.1.jar:dagger/Binds.class, obj\Debug\100\lp\69\jl\dagger.jar:dagger/Binds.class
    Compilation failed
    MSB6006: "java.exe" exited with code 1.
    Done executing task "D8" -- FAILED.
    Done building target "_CompileToDalvik" in project "Test.csproj" -- FAILED.
    Done building project "Test.csproj" -- FAILED.
    Build FAILED.
    1>Deployment failed to pixel_2_q_10_0_-_api_29.
    ========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
    

    ...so I removed the Dagger binding lib that came from the native SDK but then another exception presented itself:

    Java.Lang.NoSuchMethodError: 'No static method checkNotNullFromProvides(Ljava/lang/Object;)Ljava/lang/Object; in class Ldagger/internal/Preconditions; or its super classes (declaration of 'dagger.internal.Preconditions' appears in /data/app/com.companyname.test-HYB0dWfCe0IWG55vN-Gnqg==/base.apk)'
    

    After some digging through the dagger jar file from the native SDK and the Xamairn.Google.Dagger .dll file I realized that checkNotNullFromProvides does not exist in Xamarin.Google.Dagger which is verson 2.27.0, whereas if I get the latest version of dagger from maven it does exist, however I cant remove Xamarin.Google.Dagger otherwise the former exception comes back again...

    Java.Lang.NoClassDefFoundError: 'Failed resolution of: Ldagger/internal/Factory;'
    

    You can see the method defined here, present in the latest dagger jar:

    I have attached the sample project I have been working through.

    I would love to know what the work around for this might be, perhaps I can have one version i.e. 2.27.0 - same as Xamarin.Google.Dagger and thus keep the nuget and also keep the android binding library but consolidate to the same version i.e. 2.27.0 and then I can add through metadata/additions what's needed for the Java.Lang.NoClassDefFoundError: 'Failed resolution of: Ldagger/internal/Factory;' just thinking out loud. Pretty sure if I have duplicate Dagger references they need to be the same version.

    Let me know if you need anything further to assist me with this :smile: appreciate the help though!

  • LeoJHarrisLeoJHarris NZMember ✭✭✭
    edited March 11

    @jezh I thought maybe if I can add the method myself through additions so I did this:

    Then I checked out the .dll generated from the daggers binding lib has the new method that is currently missing

    But doesnt work :neutral:

    Java.Lang.NoSuchMethodError: 'No static method checkNotNullFromProvides(Ljava/lang/Object;)Ljava/lang/Object; in class Ldagger/internal/Preconditions; or its super classes (declaration of 'dagger.internal.Preconditions' appears in /data/app/com.companyname.test-ftMv7qb6rVWPP73zEP1HmQ==/base.apk)'
    

    Correct me if wrong but I think my best bet is keep the Xamarin.Google.Dagger nuget and include the jar in the dagger binding library as the same version and modify the dagger binding library project and deal with this checkNotNullFromProvides no such method some how.... keen to get thoughts on this though!

  • Tracy320Tracy320 Member ✭✭✭

    I wonder if you've finally solved the problem?

  • LeoJHarrisLeoJHarris NZMember ✭✭✭
    edited March 16

    @Tracy320 yes did find the answer. There were some issues with previous Dagger version i.e. 27.7.0 with some methods missing that existed in recent dagger versions that some jar dependancy libs I had relied on. So to keep the methods in latest dagger version and try fix Factory exception I got the latest dagger version from maven search and looked at the fixes made in the Xamarin.Google.Dagger, those fixes resolved the following exception:

    Java.Lang.NoClassDefFoundError: 'Failed resolution of: Ldagger/internal/Factory;'

    Check them out here: https://github.com/xamarin/XamarinComponents/blob/master/Android/GoogleDagger/source/Dagger/Transforms/Metadata.xml

    As a side note you cannot also have two references of dagger that are different versions. So I stuck to the latest and made a binding library from it with the fixes mentioned.

Sign In or Register to comment.