Hi,
I stumbled upon this project and wanted to give it a try with Android Studio and Gradle.
I have a simple Model:
package de.stelleberatung.robobinder;
import org.robobinding.presentationmodel.PresentationModel;
import javax.annotation.concurrent.ThreadSafe;
/**
* Created by stas on 2/16/14.
*/
@ThreadSafe
@PresentationModel
public class Model {
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
An activity:
package de.stelleberatung.robobinder;
import android.app.Activity;
import android.os.Bundle;
import org.robobinding.binder.Binders;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Binders.bind(this, R.layout.activity_main, new Model());
}
}
And a layout file:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://robobinding.org/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/mStatusText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
bind:text="{status}"
android:text="@string/inittext" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/mUpdateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/updatetext" />
<Button
android:id="@+id/mQuitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quit" />
</LinearLayout>
</LinearLayout>
When I assemble this with gradle I get:
I/ActivityManager( 598): Start proc de.stelleberatung.robobinder for activity de.stelleberatung.robobinder/.MainActivity: pid=12214 uid=10180 gids={50180}
I/ActivityManager( 598): Killing 11313:org.leetzone.android.yatsewidgetfree/u0a118 (adj 15): empty #17
W/MediaFocusControl( 598): RemoteControlClient died
D/AndroidRuntime(12214): Shutting down VM
W/dalvikvm(12214): threadid=1: thread exiting with uncaught exception (group=0x4198aba8)
E/AndroidRuntime(12214): FATAL EXCEPTION: main
E/AndroidRuntime(12214): Process: de.stelleberatung.robobinder, PID: 12214
E/AndroidRuntime(12214): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.stelleberatung.robobinder/de.stelleberatung.robobinder.MainActivity}: org.robobinding.binder.ViewHierarchyInflationErrorsException: -------------------------TextView(1 errors)-----------------------
E/AndroidRuntime(12214): text: You are binding to property 'status' but presentation model 'de.stelleberatung.robobinder.Model' is not observable. You either have to annotate your presentation model with @PresentationModel or implement interface ObservableProperties
E/AndroidRuntime(12214):
E/AndroidRuntime(12214):
E/AndroidRuntime(12214): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
E/AndroidRuntime(12214): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
E/AndroidRuntime(12214): at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime(12214): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime(12214): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(12214): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(12214): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime(12214): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(12214): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(12214): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime(12214): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime(12214): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(12214): Caused by: org.robobinding.binder.ViewHierarchyInflationErrorsException: -------------------------TextView(1 errors)-----------------------
E/AndroidRuntime(12214): text: You are binding to property 'status' but presentation model 'de.stelleberatung.robobinder.Model' is not observable. You either have to annotate your presentation model with @PresentationModel or implement interface ObservableProperties
E/AndroidRuntime(12214):
E/AndroidRuntime(12214):
E/AndroidRuntime(12214): at org.robobinding.binder.BindingViewInflater.inflateView(BindingViewInflater.java:63)
E/AndroidRuntime(12214): at org.robobinding.binder.BindingViewInflater.inflateView(BindingViewInflater.java:58)
E/AndroidRuntime(12214): at org.robobinding.binder.InternalBinder.inflateAndBind(InternalBinder.java:50)
E/AndroidRuntime(12214): at org.robobinding.ActivityBinder.inflateAndBind(ActivityBinder.java:37)
E/AndroidRuntime(12214): at org.robobinding.binder.Binders.bind(Binders.java:37)
E/AndroidRuntime(12214): at de.stelleberatung.robobinder.MainActivity.onCreate(MainActivity.java:13)
E/AndroidRuntime(12214): at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime(12214): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime(12214): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
E/AndroidRuntime(12214): ... 11 more
W/ActivityManager( 598): Force finishing activity de.stelleberatung.robobinder/.MainActivity
W/ActivityManager( 598): Activity pause timeout for ActivityRecord{422cdbf0 u0 de.stelleberatung.robobinder/.MainActivity t91 f}
I/ActivityManager( 598): Killing 11483:com.google.android.deskclock/u0a14 (adj 15): empty #17
I assume this is closely related to #99 . So I tried to enable AspectJ with this build using gradle. I followed this thread: http://stackoverflow.com/questions/17245402/android-new-build-system-gradle-and-aspectj
To get a gradle build file which hopefully interweaves the required aspects.
My gradle file looks like this at the moment:
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/groups/public" }
}
apply plugin: 'android'
configurations {
ajc
aspects
ajInpath
}
dependencies {
ajc "org.aspectj:aspectjtools:1.7.3"
compile "org.aspectj:aspectjrt:1.7.3"
compile 'org.robobinding:robobinding:0.8.2-SNAPSHOT'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.applicationVariants.all { variant ->
variant.javaCompile.doLast {
def androidSdk = android.adbExe.parent + "/../platforms/" + android.compileSdkVersion + "/android.jar"
def iajcClasspath = configurations.compile.asPath + ";" + androidSdk
configurations.compile.dependencies.each { dep ->
if(dep.hasProperty("dependencyProject")) {
iajcClasspath += ":" + dep.dependencyProject.buildDir + "/bundles/release/classes.jar"
}
}
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc (
source:sourceCompatibility,
target:targetCompatibility,
destDir:"${project.buildDir}/classes/${variant.dirName}",
maxmem:"512m",
fork:"true",
aspectPath:configurations.aspects.asPath,
inpath:configurations.ajInpath.asPath,
sourceRootCopyFilter:"**/.svn/*,**/*.java",
classpath:iajcClasspath
){
sourceroots{
android.sourceSets.main.java.srcDirs.each{
pathelement(location:it.absolutePath)
}
pathelement(location:"${project.buildDir}/source/r/${variant.dirName}")
}
}
}
}
However, it is still not working.
Im not that familiar with AspectJ. Most likely its just a detail that is missing.
Anyone around here who got robobinding working with gradle?