Roboblender annotation processing not working - android

I try to make Roboblender work with Roboguice but the compile time processing doesn't seem to do anything, the AnnotationDatabaseImpl class is not generated. (Project builds without error.)
I even created a sample project, please see below. What do I miss?
(I know the gradle task and the second metadata would only be needed for multi module project, but it didn't work without them either).
build.gradle:
project.tasks.withType(JavaCompile) { task ->
options.compilerArgs << "-AguiceAnnotationDatabasePackageName=gk.com.roboguice_compile"
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'org.roboguice:roboguice:3.+'
provided 'org.roboguice:roboblender:3.+'
}
manifest:
<meta-data
android:name="roboguice.modules"
android:value="gk.com.roboguice_compile.RoboguiceBindings" />
<meta-data
android:name="roboguice.annotations.packages"
android:value="gk.com.roboguice_compile" />
activity:
#ContentView(R.layout.activity_main)
public class MainActivity extends RoboActivity {
#Inject
private PresentMaker presentMaker;
bindings:
public class RoboguiceBindings extends AbstractModule {
#Override
protected void configure() {
bind(PresentMaker.class).to(BirthdayPresentMaker.class);
}
}

The AnnotationDatabaseImpl was there but only under the build directory not among the source files.
My bad, probably every annotation processor work like this.
(Although strangely this project has the AnnotationDatabaseImpl generated in the project root..).

Related

Parceler class not generating error in Android

I have a core branch where following dependencies is decalared
implementation "org.parceler:parceler-api:$rootProject.ext.parcelVersion"
annotationProcessor "org.parceler:parceler:$rootProject.ext.parcelVersion"
I am declaring a dependency in one of my library module as below
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':core')
}
Here is the class that I will be parceling in my activity
#Parcel(parcelsIndex = false)
public class MyClass {
#SerializedName("validation")
public String myField;
}
Exception is thrown at the third line.
MyClass myClass = new MyClass();
myClass.myField = "bjbskas";
Parcelable parcelable =Parcels.wrap(myClass);
Exception reads as shown below
Unable to find generated Parcelable class for com.example.mylibrary.MyClass,
verify that your class is configured properly and that the Parcelable class
com.example.mylibrary.MyClass$$Parcelable is generated by Parceler.
If I try putting the parceler library in my library module directly, it gives me another error called
Program type already present: org.parceler.Parceler$$Parcels$1
Changing the version of Parceler library from 1.0.4 to 1.1.10 solved the problem. I don't know what is the reason behind this but I guess it may be because of some transitive dependencies using version 1.1.10

Android Studio dependencies of module not visible in other module

I have a module called "Common" as library, this module has few dependencies like: com.badlogicgames.gdx, com.squareup.wire etc. And it works fine, I use them inside of this module.
And I have another module called "Tracking", where in the gradle I have:
dependencies {
compile project(':Common')
}
And if I try there to import any public class of module "Common", it works fine, but if I try to import any class of library com.badlogicgames.gdxor com.squareup.wire, it says me "Cannot resolve symbol ..." and hightlight it red. And no code autocompleting for such classes.
However the project compiles and starts on the device without errors.
Has somebody any idea? I tried "clean and rebuild" for project, "invalidate cashes and restart" for Android Studio. Nothing helps.
in the module common you need to declare those transitive dependencies as api to expose them to other modules:
e.g. common/build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
api 'com.squareup.wire'
}
https://jeroenmols.com/blog/2017/06/14/androidstudio3/
Solution
Change compile to api
dependencies {
api project(':Common')
}
Reason
Because compile is deprecated, so it is been treated as implementation.
FYI compile and api (new keyword for compile) are same in which all internal modules are visible.
But new gradle project having compile keyword are treated as implementation. and in implementation internal modules are not visible to main project.
Suggestion
You should declare dependency in your gradle because it is not good to make leak of internal modules.

Stetho - Android Studio Initialization

I am having trouble trying to use Stetho, I've tried to search and follow the steps provided by others but, it seems none of them highlight my problem. Below is what is in my needed files for Stetho utilization.
My problem is it cannot identify the method "initialize" I've tried other ways of implementing the method through the suggestion of other users but, I still meet the same error
build.gradle (Module: app)
dependencies {
compile 'com.facebook.stetho:stetho:1.5.0'
compile 'com.facebook.stetho:stetho-okhttp3:1.5.0'
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'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
}
in my Stetho Application Class
import android.app.Application;
public class Stetho extends Application {
#Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
declared in my Manifest
<application
android:name=".Stetho"
android:allowBackup="true"
I thought the problem is, I don't actually have the library implemented correctly, but I am not sure.
You are probably getting name conflicts because your App class is named Stetho as well. Rename your App class on the .java and .manifest files. Import the Stetho package into your app class.
Your app class should look something like this:
import android.app.Application;
import com.facebook.stetho.Stetho;
public class MyApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
And your manifest like this:
<application
android:name=".MyApp"
android:allowBackup="true" />

Android Studio Autovalue in java module and using in Android module

Using Android Studio I have an Android Module, and a Java module.
In the Java module, I want to use AutoValue to generate immutable classes.
All seems to work fine (files are generated in the Java module) but I'm unable to access those files in the Android project. Any suggestions?
app\build.gradle
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':domain')
}
domain\build.gradle
plugins {
id 'net.ltgt.apt' version '0.6'
}
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.auto.value:auto-value:1.2'
apt 'com.google.auto.value:auto-value:1.2'
}
domain/MyLocation.java
import com.google.auto.value.AutoValue;
#AutoValue
abstract class MyLocation {
abstract String name();
#AutoValue.Builder
abstract static class Builder {
abstract Builder name(String _name);
abstract MyLocation build();
}
}
When I build the domain module (the java module), I see that the 'AutoValue_MyLocation' file is generated here:
\domain\build\generated\source\apt\main\my\package\domain\AutoValue_MyLocation.java
However, I am not able to use the generated class anywhere in my Android module.
Nevermind, by looking at the generated class I saw that it was not public, hence I could not access it in my Android Module.
To fix it, simple make the #AutoValue class public, like so
#AutoValue
public abstract class MyLocation {
//
}

RoboGuice 3.0 NoClassDefFoundError: AnnotationDatabaseImpl

For some reason the RoboBlender does not generate the annotation database.
My build.gradle has the following dependencies:
dependencies {
provided 'org.roboguice:roboblender:3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.roboguice:roboguice:3.0'
}
This is not a final solution, but it can help you. I don't know why, but RoboGuice 3.0 and 3.0.1 throws this exception. What you have to do is disable annotations for databases in your MainActivity as follows:
static {
RoboGuice.setUseAnnotationDatabases(false);
}
I hope this help
Ok, so it seems that since I didn't have any injection in the main class MainActivity it didn't trigger the annotation processing of the inner AsyncTask. Therefore no annotation database was created.
Moreover, it seems that injection in anonymous inner classes is not supported. So the AsyncTask needs to be a proper class (it can still be inside the MainActivity).
I haven't figured out yet how to tell RoboGuice to inspect the inner classes even though the outer one does not have injections.
What does the rest of your project structure look like?
Specifically, have you read the RoboBlender wiki
Later versions of Android Studio will, by default, generate a project that falls into the Configuring RoboBlender for a large application using libraries-category.
Fix below does the following:
Rearrange dependencies in build.gradle
Supplies pointer to GuiceModule in project
Rudimentary module for your project
diff --git a/app/build.gradle b/app/build.gradle
index 1e69cec..8450fff 100644
--- a/app/build.gradle
+++ b/app/build.gradle
## -34,9 +34,9 ## android {
}
dependencies {
- provided 'org.roboguice:roboblender:3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.roboguice:roboguice:3.0'
+ provided 'org.roboguice:roboblender:3.0'
}
project.tasks.withType(JavaCompile) { task ->
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 017d11e..dba9e49 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
## -8,6 +8,7 ##
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="roboguice.annotations.packages" android:value="org.jush.roboguice3test"/>
+ <meta-data android:name="roboguice.modules" android:value="org.jush.roboguice3test.GuiceModule"/>
<activity
android:name="org.jush.roboguice3test.MainActivity"
android:label="#string/app_name" >
package org.jush.roboguice3test;
import android.app.Application;
import com.google.inject.AbstractModule;
public class GuiceModule extends AbstractModule {
private Application application;
public GuiceModule(Application application) {
this.application = application;
}
#Override
protected void configure() {
}
}
What did you have to do that it did trigger the annotation processing? My main activity has injections. The maina activity inherits from an abstract activity which has as well injections. That abstract activity inherits from RoboActivity.
When i set the roboguice.annotations.packages to roboguice the NoClassFound exception isn't thrown anymore, but i get a NullPointer Exception for the first inject-Object that I wanna use.
I use eclipse to start the app.
When I disable RoboBlender (RoboGuice.setUseAnnotationDatabases(false);) injection works.
The AnnotationDatabaseImpl is generated at compile time
An explanation is available here
Injected objects became null after upgrading to Roboguice 3

Categories

Resources