Reputation: 266
I am getting a build error as soon as I enable dataBinding for my library project:
AAPT: No resource type specified (at 'text' with value '@{user.name}')
If I enable dataBinding for the application module, it works fine. But if I enable dataBinding for my lib project, I get the above error.
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')
}
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'
}
The 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>
@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);
}
public class User extends BaseObservable {
private final String name;
public User(String name){
this.name = name;
}
@Bindable
public String getName() {
return name;
}
}
Thanks
Upvotes: 3
Views: 2540
Reputation: 266
Figured out the issue. The package structure messed up things for me. The package structure in the manifest and the actual package structure was different. Reason being we are dealing with legacy codebase and it got overlooked. It is working fine.
Upvotes: 1
Reputation: 38253
It does work with library projects but any app that depends on a library that uses data binding has to enable data binding even if they don't use it.
Upvotes: 3