Android aar库不包含BR类

时间:2016-10-20 09:58:07

标签: android android-library aar android-databinding

我开发了一个小型库,用于通过数据绑定来测试aar库创建。

我的问题是当我生成aar文件时,它不包括为布局中的数据绑定引用生成的BR类。但该类已由Android Studio生成。

你有解决方案来解决这个问题吗?

提前致谢。

的build.gradle

apply plugin: 'com.android.library'
apply plugin: 'android-maven'

android {
    signingConfigs {
        release {
            keyAlias 'homelightcore'
            keyPassword 'overcraft'
            storeFile file('/Users/acidspike/Development/Certificats/Android/HomeLight/Core/homelightcore.jks')
            storePassword 'overcraft'
        }
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    dataBinding {
        enabled = true
    }
}

version '1.0'
group "fr.acidspike.homelight"

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.4.0'
    testCompile 'junit:junit:4.12'
    compile 'com.loopj.android:android-async-http:1.4.9'
}

proguard-rules.pro

-keep public class *

-keepclassmembers public class * {
   public *;
}

-keepattributes Exceptions

1 个答案:

答案 0 :(得分:0)

I found the solution, it's because proguard doesn't detect usage of the BR class members.

I have added :

-keepclassmembers class **.R$* {
    public static <fields>;
}

into the proguard-rules.pro and the BR class become available from the .aar