Greenrobot Android Eventbus - No option eventbusindex passed to annotation processor - android

I'm trying to set up a simple subscriber in my Android application using Greenrobot's Eventbus, but I am getting a gradle build error. I have shown my code below.
Event class
public final class OffersProcessedEvent {}
Base Fragment
public class BaseFragment extends Fragment {
private boolean registered;
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
EventBus.getDefault().register(this);
registered = true;
}
#Override
public void onResume() {
super.onResume();
if (!registered) {
EventBus.getDefault().register(this);
registered = true;
}
}
#Override
public void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
registered = false;
}
public AppCompatActivity getAppCompatActivity() {
return (AppCompatActivity) getActivity();
}
}
Event post'
EventBus.getDefault().post(new OffersProcessedEvent());
Subscribe code
#Subscribe
public void onMessageEvent(OffersProcessedEvent event){
*do whatever*
}
The following are my errors
Build Gradle Errors
Error:No option eventBusIndex passed to annotation processor
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Gradle dependencies
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:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.jakewharton:butterknife:8.6.0'
compile 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.jakewharton:butterknife:8.7.0'
compile 'com.jakewharton:butterknife-compiler:8.7.0'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
compile 'com.google.code.gson:gson:2.8.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'org.greenrobot:eventbus-annotation-processor:3.0.1'
}

apply plugin: 'kotlin-kapt' // ensure kapt plugin is applied
dependencies {
implementation 'org.greenrobot:eventbus:3.1.1'
kapt 'org.greenrobot:eventbus-annotation-processor:3.1.1'
}
kapt {
arguments {
arg('eventBusIndex', 'com.example.myapp.MyEventBusIndex')
}
}

Base on this link http://greenrobot.org/eventbus/documentation/faq/
This happens when you set up the build script, and you did not add any
annotations to your code yet. Without any #Subscribe annotations,
annotation processor for indexing will not be triggered to consume the
‘eventBusIndex’ option. So, just add some #Subscribe annotations and
you should be fine.
So you must add
#Subscribe
fun onEvent(event: SomeEvent) {
}
But is you steel getting Error:No option eventBusIndex passed to annotation processor
Add this to your app.gradle
If using annotationProcessor
defaultConfig {
//other code
javaCompileOptions {
annotationProcessorOptions {
arguments = [eventBusIndex: "com.example.myapp.MyEventBusIndex"]
}
}
}
If using kapt
dependencies {
//other codes
}
kapt {
arguments {
arg('eventBusIndex', 'com.example.myapp.MyEventBusIndex')
}
}
And if using android-apt
dependencies {
//other codes
}
apt {
arguments {
eventBusIndex "com.example.myapp.MyEventBusIndex"
}
}
And this file will be generate by EventBus
/** This class is generated by EventBus, do not edit. */
public class MyEventBusIndex implements SubscriberInfoIndex {
private static final Map<Class<?>, SubscriberInfo> SUBSCRIBER_INDEX;
static {
SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();
putIndex(new SimpleSubscriberInfo(MainActivity.class, true, new SubscriberMethodInfo[] {
new SubscriberMethodInfo("onBleClick", com.example.myapp.Events.BleClickListener.class),
}));
}
private static void putIndex(SubscriberInfo info) {
SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info);
}
#Override
public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) {
SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass);
if (info != null) {
return info;
} else {
return null;
}
}
}
Hope it's help

Related

crash in Android only, java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/MediaType;

Update: Its only crashing on Android Lollipop.
I am getting this error
06-08 16:30:56.788 29535-29535/com.d.p E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.d.p, PID: 29535
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/MediaType;
at com.d.p.ui.base.DWBApplication.<clinit>(DWBApplication.java:164)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
at android.app.Instrumentation.newApplication(Instrumentation.java:1000)
at android.app.Instrumentation.newApplication(Instrumentation.java:985)
at android.app.LoadedApk.makeApplication(LoadedApk.java:567)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4837)
at android.app.ActivityThread.access$1500(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1531)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.okhttp.MediaType" on path: DexPathList[[zip file "/data/app/com.d.p-1/base.apk", zip file "/data/app/com.d.p-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.d.p-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.d.p.ui.base.DWBApplication.<clinit>(DWBApplication.java:164) 
at java.lang.reflect.Constructor.newInstance(Native Method) 
at java.lang.Class.newInstance(Class.java:1606) 
at android.app.Instrumentation.newApplication(Instrumentation.java:1000) 
at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
at android.app.LoadedApk.makeApplication(LoadedApk.java:567) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4837) 
at android.app.ActivityThread.access$1500(ActivityThread.java:178) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1531) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5643) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
Suppressed: java.lang.ClassNotFoundException: com.squareup.okhttp.MediaType
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
My gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
// compile 'com.google.android.gms:play-services-location:8.4.0'
compile('com.github.worker8:tourguide:1.0.17-SNAPSHOT#aar') {
transitive = true
}
compile 'junit:junit:4.12'
compile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.android.support:design:25.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.wefika:flowlayout:0.4.1'
compile 'com.jeremyfeinstein.slidingmenu:library:1.3#aar'
compile 'com.googlecode.libphonenumber:libphonenumber:7.0.4'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.commit451:PhotoView:1.2.5'
compile 'com.outlander.showcaseview:showcaseview:1.2.0'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'com.google.firebase:firebase-crash:9.0.0'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'
compile 'com.google.android.gms:play-services-analytics:9.4.0'
compile 'com.layer.sdk:layer-sdk:0.21.3'
compile 'org.slf4j:slf4j-nop:1.5.8'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.layer.atlas:layer-atlas:0.2.10'
compile 'io.jsonwebtoken:jjwt:0.6.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
apply plugin: 'com.google.gms.google-services'
My application file:
public class DWBApplication extends Application {
//Network interface for executing web services over internet
Retrofit networkInterfaceBuilder;
private DawaiBoxService dawaiboxServiceInterface;
//Holds the current application context
private static Context appContext;
private static HomeActivity homeActivity; //Holds the reference to homeActivity as it holds fragments.
// Some time 'onAttach' callback method may call slowly. So then homeActivity reference is used from here
private static DWBApplication mInstance;
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
ViewTarget.setTagId(R.id.glide_tag);
mInstance = this;
// firebase initialization
FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(true);
// google analytics initialization
AnalyticsTrackers.initialize(this);
AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);
if(BuildConfig.FABRIC_ENABLED){
Fabric.with(this, new Crashlytics());
}
appContext = getApplicationContext();
//Create builder for interacting to server
networkInterfaceBuilder = new Retrofit.Builder()
.baseUrl(BuildConfig.SERVER_URL)
.addConverterFactory(new GsonStringConverterFactory())
.addConverterFactory(GsonConverterFactory.create())
.build();
//Create service interface to execute dawaibox services
dawaiboxServiceInterface = networkInterfaceBuilder.create(DawaiBoxService.class);
try {
//initialize Typefaces
TypefaceUtils.initTypefaces(getApplicationContext());
} catch (Exception ex) {
DWB_Logs.e("typefaces", ex);
}
}
public DawaiBoxService getDawaiboxServiceInterface() {
return dawaiboxServiceInterface;
}
public static Context getAppContext() {
return appContext;
}
/*------------------------------Current user reference methods ends---------------------*/
/*------------------------------Add prefix +91 to mobile no. Methods starts---------------------*/
/*
* Desc: appends the '+91' prefix to entered text in edit text.
* */
public static MobileNoTextWatcher getAppendPrefixTextWatcher() {
return new MobileNoTextWatcher();
}
public static String getMobileNoFromEdTxt(EditText mMobileNoEd) {
if (mMobileNoEd.getText() != null) {
String mobileNo = mMobileNoEd.getText().toString();
if (mobileNo.length() > Constants.MOBILE_PREFIX.length()) {
return mobileNo.substring(Constants.MOBILE_PREFIX.length(), mobileNo.length());
}
}
return "";
}
/*------------------------------Add prefix +91 to mobile no. Methods ends---------------------*/
/*------------------------------Base homeActivity holder methods starts---------------------*/
/*Set the reference to current base homeActivity which displays the fragments*/
public static void setHomeActivity(HomeActivity homeActivity) {
DWBApplication.homeActivity = homeActivity;
}
/*Returns the reference of current base homeActivity which displays the fragments*/
public static HomeActivity getHomeActivity() {
return homeActivity;
}
/*------------------------------Base homeActivity holder methods ends---------------------*/
/*
* Methods which will hides the keyboard*/
public static void hideSoftKeyboard(Activity activity) {
try {
activity.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);
} catch (Exception ex) {
ex.printStackTrace();
}
}
/*
* Solves problem: adding extra quotes to multipart string form values
*/
private static final MediaType MEDIA_TYPE = MediaType.parse("text/plain");
public class GsonStringConverterFactory extends Converter.Factory {
#Override
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
if (String.class.equals(type))// || (type instanceof Class && ((Class<?>) type).isEnum()))
{
return new Converter<String, RequestBody>() {
#Override
public RequestBody convert(String value) throws IOException {
return RequestBody.create(MEDIA_TYPE, value);
}
};
}
return null;
}
}
public static synchronized DWBApplication getInstance() {
return mInstance;
}
public synchronized Tracker getGoogleAnalyticsTracker() {
AnalyticsTrackers analyticsTrackers = AnalyticsTrackers.getInstance();
return analyticsTrackers.get(AnalyticsTrackers.Target.APP);
}
/***
* Tracking screen view
*
* #param screenName screen name to be displayed on GA dashboard
*/
public void trackScreenView(String screenName) {
Tracker t = getGoogleAnalyticsTracker();
// Set screen name.
t.setScreenName(screenName);
// Send a screen view.
t.send(new HitBuilders.ScreenViewBuilder().build());
//t.set("&uid", DWB_SharedPreferences.getLayertID(this));
GoogleAnalytics.getInstance(this).dispatchLocalHits();
}
/***
* Tracking exception
*
* #param e exception to be tracked
*/
public void trackException(Exception e) {
if (e != null) {
Tracker t = getGoogleAnalyticsTracker();
t.send(new HitBuilders.ExceptionBuilder()
.setDescription(
new StandardExceptionParser(this, null)
.getDescription(Thread.currentThread().getName(), e))
.setFatal(false)
.build()
);
}
}
/***
* Tracking event
*
* #param category event category
* #param action action of the event
* #param label label
*/
public void trackEvent(String category, String action, String label) {
Tracker t = getGoogleAnalyticsTracker();
t.set("&uid", Config.USER1);
// Build and send an Event.
t.send(new HitBuilders.EventBuilder().setCategory(category).setAction(action).setLabel(label).build());
}
}
I am getting crash on private static final MediaType MEDIA_TYPE = MediaType.parse("text/plain"); line in application.java
Just a guess, but the error exists in a transitive dependency of Retrofit called Okhttp.
Retrofit is not in beta anymore. You can go through and upgrade your libraries.
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit:converter-gson:2.3.0'
Personally, I would rewrite like so in order to always keep versions consistent
ext {
retrofitVer = '2.3.0'
}
dependencies {
...
compile "com.squareup.retrofit2:retrofit:${retrofitVer}"
compile "com.squareup.retrofit:converter-gson:${retrofitVer}"
}
The same should be applied to the support libraries, Google play and Firebase

FirebaseListAdapter not firing populateView()

After finding some people saying that FirebaseRecyclerAdapters are broken inside of fragments (and trying for about 4 hours to get it to work before that), I decided to switch to a FirebaseListAdapter, as I found examples of that working inside of fragments. However, I'm having issues. The populateView() method never seems to be firing and I'm getting no errors. Here is my code for the fragment:
public class PasteFromFirebasePopup extends DialogFragment implements AdapterView.OnClickListener {
Activity activity;
private FirebaseListAdapter mFirebaseAdapter;
private DatabaseReference mClipboardHistoryReference;
private ListView mListView;
public PasteFromFirebasePopup() {}
#Override public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.clip_history_popup_list, container, false);
mListView = (ListView) rootView.findViewById(R.id.clipboardHistoryListView);
activity = getActivity();
mClipboardHistoryReference = FirebaseDatabase.getInstance().getReference(Constants.FIREBASE_CHILD_CLIPBOARD_HISTORY);
Log.d("clipboardRef", mClipboardHistoryReference.toString());
mFirebaseAdapter = new FirebaseListAdapter<FirebaseString>
(activity, FirebaseString.class, R.layout.clip_history_popup_item, mClipboardHistoryReference) {
TextView mTextView;
#Override protected void populateView(View v, FirebaseString model, int position) {
mTextView = (TextView) v.findViewById(R.id.clipboardHistoryTextView);
Log.d("model text", model.getText());
mTextView.setText(model.getText());
}
};
mListView.setAdapter(mFirebaseAdapter);
return rootView;
}
#Override public void onClick(View v) {}
#Override public void onDestroy() {
super.onDestroy();
mFirebaseAdapter.cleanup();
}
}
No matter what I try, the log inside of populateView() absolutely never fires. I have triple checked my reference, and there is indeed something in there (only one item at the moment, but as far as I can tell that shouldn't matter). Am I missing something? Does this not work inside of DialogFragments? If not, does anyone have a suggestion for a popup that can hold a FirebaseListAdapter/RecyclerAdapter successfully?
Any help is duly appreciated.
EDIT: my build.gradle (app) , as I think this may have something to do with it.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.github.smart-fun:XmlToJson:1.2.2'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-database:11.0.0'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.google.android.gms:play-services:11.0.0'
compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.google.gms.google-services'

unfortunately package installer has stopped

Background: I'm trying to make a simple with RxPermissions .. I created a new project with the bellow code/setup but when I launch the app I got a dialog with the message "unfortunately package installer has stopped"
gradle.build
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.7.0#aar'
compile 'io.reactivex:rxandroid:1.2.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex:rxjava:1.1.6'
}
MainActivity.java
public class MainActivity extends Activity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Must be done during an initialization phase like onCreate
((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View view) {
RxPermissions.getInstance(MainActivity.this)
.request(Manifest.permission.CAMERA)
.subscribe(new Action1<Boolean>() {
#Override public void call(Boolean aBoolean) {
}
});
}
});
}
}
I forgot to declare the permission Manifest.permission.CAMERA in the manifest.

Realm.io / Dagger / Databinding in the same project

I am having issues with compiling my project after I added Realm.io as a dependency via gradle. The generated files created by dagger and databinding can not be found. If I remove realm.io the app compiles correctly.
Here is my build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.android.databinding'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
multiDexEnabled true
applicationId "com.foo"
minSdkVersion 15
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'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.facebook.stetho:stetho:1.2.0'
compile 'com.facebook.stetho:stetho-okhttp:1.2.0'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'io.reactivex:rxjava:1.0.14'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okio:okio:1.4.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:design:23.1.0'
compile 'com.jakewharton.timber:timber:4.1.0'
compile 'io.realm:realm-android:0.85.1'
compile 'com.google.dagger:dagger:2.0.1'
provided 'javax.annotation:jsr250-api:1.0'
apt "com.google.dagger:dagger-compiler:2.0.1"
apt 'com.android.databinding:compiler:1.0-rc4'
}
I see that Realm is also generating files and maybe the compilers are not playing nice together. Any ideas on how to get this working?
Thanks
I see that you also received the error:
No setter found for field goalInfo
Make sure the field names are the same as the getters and setters. Do not prepend "m" to the field names. Example:
#RealmClass
public Goal extends RealmObject {
//private String mGoalInfo;
private String goalInfo;
public String getGoalInfo() {
return goalInfo;
}
public void setGoalInfo(String goalInfo) {
this.goalInfo = goalInfo;
}
}
Databinding works with RealmObjects, but you have to implement Observable.
public class Post extends RealmObject implements Observable {
#PrimaryKey
private long id;
private String text;
#Ignore
private transient PropertyChangeRegistry mCallbacks;
#Bindable
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
if(!isValid()) { // !isManaged() in Realm 2.0
notifyPropertyChanged(BR.id);
}
}
#Bindable
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
if(!isValid()) { // !isManaged() in Realm 2.0
notifyPropertyChanged(BR.text);
}
}
#Override
public synchronized void addOnPropertyChangedCallback(OnPropertyChangedCallback callback) {
if (mCallbacks == null) {
mCallbacks = new PropertyChangeRegistry();
}
mCallbacks.add(callback);
}
#Override
public synchronized void removeOnPropertyChangedCallback(OnPropertyChangedCallback callback) {
if (mCallbacks != null) {
mCallbacks.remove(callback);
}
}
/**
* Notifies listeners that all properties of this instance have changed.
*/
public synchronized void notifyChange() {
if (mCallbacks != null) {
mCallbacks.notifyCallbacks(this, 0, null);
}
}
/**
* Notifies listeners that a specific property has changed. The getter for the property
* that changes should be marked with {#link Bindable} to generate a field in
* <code>BR</code> to be used as <code>fieldId</code>.
*
* #param fieldId The generated BR id for the Bindable field.
*/
public void notifyPropertyChanged(int fieldId) {
if (mCallbacks != null) {
mCallbacks.notifyCallbacks(this, fieldId, null);
}
}
}
And Dagger + Databinding can break each other, for which you need to add
apt 'com.google.guava:guava:19.0' // dagger + databind workaround
Realm, Dagger2 and Databinding are all working in my project.
The difference is:
I'm using android gradle plugin 1.5.0 and enable databinding by following configuration.
android {
...
dataBinding {
enabled = true
}
...
}
And I don't have
apt 'com.android.databinding:compiler:1.0-rc4'
in dependencies.
Whole working project is here: https://github.com/zaki50/realm_template
It is now possible to implement the RealmModel interface and add an annotation #RealmClass to the class instead of extending RealmObject. This lets you extends BaseObservable however it is still not working.
You get a databinding error: package mypackage.databinding does not exist
See this issue on github: https://github.com/realm/realm-java/issues/2716

Junit Test report (XML/HTML) not generated in android studio

public class StringUtilsTests extends TestCase {
String message;
#Override
protected void setUp() throws Exception {
super.setUp();
message = "33,333";
}
/**
*
*/
public void testCommaToSpaces() {
String result = StringUtils.commasToSpaces(message);
assertEquals("33 333", result);
}
}
build.gradle :-
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services-plus:7.5.0'
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.code.gson:gson:2.3.1'
// Unit testing dependencies
testCompile 'junit:junit:4.12'
// Set this dependency if you want to use Mockito
testCompile 'org.mockito:mockito-core:1.10.19'
}
testOptions {
unitTests.all {
// All the usual Gradle options.
jvmArgs '-XX:MaxPermSize=256m'
}
}
sourceSets {
unitTest {
java.srcDir file('src/androidTest/java')
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/results-tests")
}
task unitTest(type: Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
check.dependsOn unitTest
I tried lot of things after googling more than a day, but test reports - xml/html are not getting generated. Please kindly guide if anyone has any idea on this.
If i add below line then gradle sync failed.
reports.html.enabled = true
Did you add the line below in your gradle script?
buildTypes {
debug {testCoverageEnabled = TEST_COVERAGE}}
There is an export results option in the test runner. Once the tests have been executed, you can export these results as .html or .xml
It's the right most option.
Click here to see where it is

Categories

Resources