简体   繁体   English

Android aar库不包含BR class

[英]Android aar library does not include BR class

I develop a small library for testing aar library creation with databinding.我开发了一个小型库,用于测试使用数据绑定创建的 aar 库。

My problem is when I generate the aar file it doesn't include the BR class generated for databinding references in layout.我的问题是当我生成 aar 文件时,它不包含为布局中的数据绑定引用生成的 BR class。 But the class has been generated by Android Studio.但是 class 是由 Android Studio 生成的。

Do you have a solution to solve this problem?你有办法解决这个问题吗?

Thanks in advance.提前致谢。

build.gradle 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 proguard-rules.pro

-keep public class *

-keepclassmembers public class * {
   public *;
}

-keepattributes Exceptions

I found the solution, it's because proguard doesn't detect usage of the BR class members. 我找到了解决方案,这是因为proguard未检测到BR类成员的使用情况。

I have added : 我已经添加了 :

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

into the proguard-rules.pro and the BR class become available from the .aar 进入proguard-rules.pro,BR类可从.aar获得

aar file is supposed to not include BR class. Instead it contains a file located at /data-binding/*-br.bin. aar 文件应该不包含 BR class。相反,它包含一个位于 /data-binding/*-br.bin 的文件。 The file gives the compiler information to generate the real BR class for apk when compiling application module.该文件给出了编译器信息,以便在编译应用程序模块时为 apk 生成真正的 BR class。 In this way, BR fields with same names but defined in different modules are guaranteed to have same values.这样,保证在不同模块中定义的具有相同名称的 BR 字段具有相同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM