EgorBo / Xamaridea

Visual Studio extension. Opens *.axml/xml files in IDEA or Android Studio (Xamarin.Android)
GNU General Public License v2.0
78 stars 22 forks source link

Android Studio 3 and mvvmcross #14

Open softlion opened 6 years ago

softlion commented 6 years ago

Hi, when a project layout file (xml) contains custom tags originating from an android library referenced in the android project (like mvvmcross), the gradle build fails as it can't find them.

It can't find them because XamarIdea does not add in app\build.gradle (in sourceSets/main/res.srcDirs tag) the obj/Debug/__library_projects__/* folders, which contains Android resources from these referenced assemblies.

A workaround is to manually update the build.gradle file and manually add each __library_projects__ folder

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.egorbo.javashallowcopyforxamarinproject"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            res.srcDirs = [
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/Resources',
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/__library_projects__/XamSvg.Droid/library_project_imports/res',
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/__library_projects__/Vapolia.WheelPickerDroid/library_project_imports/res',
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/__library_projects__/MvvmCross.Binding.Droid/library_project_imports/res',
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/__library_projects__/MvvmCross.Droid.Support.V7.RecyclerView/library_project_imports/res'
            ]
        }
    }
}
softlion commented 6 years ago

Update for VS2017 15.5

In VS2017 version 15.5, the __library_projects__ folders have been replaced by the "lp" folders. The folder structure seems to be lp\xx\jl\res\values\... where xx is a number.

This updated version fix the problem, hoping Xamarin won't change the xx "number" after every compilation.

            res.srcDirs = [
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/Resources',
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/lp/71/jl/res', //XamSvg
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/lp/41/jl/res', //WheelPicker
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/lp/14/jl/res', //Mvvmcross Binding
                    'C:/Dev/repos/totoapp/Toto/Toto.Droid/obj/Debug/lp/20/jl/res', //Mvvmcross RecyclerView
            ]
pedroccrl commented 6 years ago

Update for VS2017 15.8, Android Compile 8.1.

The folder structure changes from .../{DroidProject}/obj/Debug/lp/xx/... to .../{DroidProject}/obj/Debug/MonoAndroid81/lp/xx/...