I generate errors immediately after I enable databinding for the Android library project
•
Android
After I enable databinding for my library project, I immediately receive a build error:
AAPT: no resource type specified (in text, the value is' @ {user. Name} ')
If I enable databinding for the application module, it will work properly. However, if I enable databinding for my lib project, I will receive the above error
Build.gradle of application module
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
dataBinding{
enabled true
}
defaultConfig {
applicationId "xyz.databindingtrial"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile project(path: ':librarytrial')
}
Build.gradle of Lib project
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
dataBinding{
enabled true
}
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
}
Layout file:
<data class="UserTrackingBinding">
<variable
name="user"
type="xyz.databindingtrial.model.User"/>
</data>
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="xyz.databindingtrial.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.name}"/>
</RelativeLayout>
Activity code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UserTrackingBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
User user = new User("Test");
binding.setUser(user);
}
User model
public class User extends BaSEObservable {
private final String name;
public User(String name){
this.name = name;
}
@Bindable
public String getName() {
return name;
}
}
Is databinding not applicable to library projects? If so, what's wrong with my settings?
thank you
resolvent:
It does apply to library projects, but any applications that rely on libraries that use data binding must enable data binding, even if they do not use it
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码