Class did not get auto generated - java

I am learning how to use Dagger2. I created an example as shown below in the code. the issue I am facing is, the auto generated class by Daggers, the one
that should be called "DaggerInterfaceComponent" is never gets created. The below DaggerInterfaceComponent is underscored with red.
Please have a look at the build gradle App posted below.
code:
InterfaceComponent component = DaggerInterfaceComponent.builder().objectValuesModule(new ObjectValuesModule()).build();
Object injectedObject = component.getObjectValues();
int returnedInt = injectedObject.getreturnInteger();
int returnedStr = injectedObject.getReturnString();
int returnedObj = injectedObject.getReturnObject();
gradle App
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'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile "com.google.dagger:dagger:2.11"
annotationProcessor "com.google.dagger:dagger-compiler:2.11"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
}

Related

Duplicate class org.apache.commons

I am trying to run a build on Android. I'm in the process of building a React-Native bridge for a Java library. However, I am getting a Duplicate class error which looks like follows:
Duplicate class org.apache.commons.lang3.builder.CompareToBuilder
found in modules commons-lang3-3.9.jar (org.apache.commons:commons-lang3:3.9)
and creditCardNfcReader-1.0.3-runtime.jar (com.github.pro100svitlo:creditCardNfcReader:1.0.3)
There are an entire list of these errors being printed out. There is also a slightly different error which looks like this:
Duplicate class bolts.BoltsExecutors$ImmediateExecutor found in
modules bolts-tasks-1.4.0.jar (com.parse.bolts:bolts-tasks:1.4.0)
and jetified-bolts-android-1.1.2.jar (com.parse.bolts:bolts-android:1.1.2)
My dependencies currently look like this in my build.gradle file:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation 'com.github.pro100svitlo:creditCardNfcReader:1.0.3'
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
I have tried to exclude modules and groups from the dependencies with no luck yet. Here are a few approaches I have tried as recommended from several sources:
1.
implementation ("com.facebook.react:react-native:+") {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
2.
implementation ("com.facebook.react:react-native:+") { exclude module: 'bolts-tasks'}
3.
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation 'com.github.pro100svitlo:creditCardNfcReader:1.0.3'
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
configurations { runtime.exclude group: '*' }
I would really appreciate any help with finding a solution to this problem. Thanks in advance.
The exclude method of the configuration closure for a dependency excludes transitive dependencies. So, if your module dependency depends on other modules, you can exclude them from your build. You can check out the transitive dependencies of the 'com.facebook.react:react-native:+' module on its maven repo.
https://mvnrepository.com/artifact/com.facebook.react/react-native/0.20.1
Try specify the version of dependency instead of use '+' to avoid conflict.
Here is some reference to check on resolving the plugins and dependency jar conflicts.
jarjar package reference

In this code I got Cannot resolve symbol R

I used the GitHub time picker dialog library and I got an error "Can not find symbol R".
1) The library I used.
implementation 'com.kovachcode:timePickerWithSeconds:1.0.1'
2) The error line code is below.
setButton(context.getText(R.string.time_set), this); // in this line
setButton2(context.getText(R.string.cancel), (OnClickListener) null);// in this line
//setIcon(android.R.drawable.ic_dialog_time);
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.time_picker_dialog, null);//in this line
setView(view);
mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);//in this line
This file is also a read-only file and not editable. Please give me a solution.
3) These are all dependencies I used.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.firebase:firebase-jobdispatcher:0.8.6'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.android.support:design:28.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.android.volley:volley:1.1.1-rc1'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'info.androidhive:fontawesome:0.0.5'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.kovachcode:timePickerWithSeconds:1.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Please check your manifest and add
tools:replace="android:icon, android:label, android:theme"
import like this in your class.
import com.yourpackage.R;
it can be error on "time_picker_dialog.xml" file or any other xml file. Can you check it?

Android Studio JRE process finished with non-zero exit value 1

With these dependencies present in build.gradle.
I am getting this error when i am trying to run the project
Process 'command '/Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with
non-zero exit value 1
/*CamerAFragment*/
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//compile "com.android.support:design:$rootProject.supportLibraryVersion"
//butterknife
// implementation 'com.jakewharton:butterknife:8.8.1'
//annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//circle indicator
implementation 'me.relex:circleindicator:1.2.2#aar'
//google plus
implementation 'com.google.android.gms:play-services-auth:11.0.4'
/*Viper*/
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"
// reactive
implementation "io.reactivex.rxjava2:rxjava:$rootProject.rxjava2Version"
implementation "io.reactivex.rxjava2:rxandroid:$rootProject.rxandroidVersion"
// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
// dependency injection
implementation "com.google.dagger:dagger:$rootProject.dagger2Version"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"
provided 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'
//multidex
implementation 'com.android.support:multidex:1.0.3'
//new start
// kapt 'com.google.dagger:dagger-android-processor:2.15'
// kapt 'com.google.dagger:dagger-compiler:2.15'
//new end
//animationasdasd
compile 'com.skyfishjy.ripplebackground:library:1.0.1'
//DrawablePageIndicator
implementation 'com.augustopicciani.drawable_page_indicator:library:1.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// AutoScrollView
implementation('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
exclude module: 'support-v4'
}
//Cropper
implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.7'
/*AWS*/
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-core:2.6.+'
/*//glide
implementation 'com.github.bumptech.glide:glide:4.5.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'*/
//Country code
implementation 'com.hbb20:ccp:2.2.2'
// implementation 'com.hbb20:ccp:2.0.3'
//Underscore
implementation 'com.github.javadev:underscore:1.28'
//pdf opener
compile 'com.github.barteksc:android-pdf-viewer:2.8.2'
//Crash
implementation 'com.google.firebase:firebase-crash:11.0.4'
/* // Check for v11.4.2 or higher
implementation 'com.google.firebase:firebase-core:15.0.0'*/
// Add dependency
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
/*Custom Camera view*/
implementation project(':Cameralibrary')
/*App purchase */
implementation 'com.android.billingclient:billing:1.0'
/*OCR demo Gradle starts from here */
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "android.arch.lifecycle:extensions:${versions.lifecycle}"
implementation "android.arch.lifecycle:common-java8:${versions.lifecycle}"
implementation "com.getkeepsafe.relinker:relinker:${versions.relinker}"
implementation 'de.greenrobot:eventbus:2.4.0'
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${versions.leak_canary}"
debugImplementation "com.squareup.leakcanary:leakcanary-android:${versions.leak_canary}"
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation "com.commit451:PhotoView:${versions.photoview}"
// implementation 'com.viewpagerindicator:library:2.4.1#aar'
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1#aar'
//butterknife
implementation "com.jakewharton:butterknife:${versions.butterknife}"
// kapt "com.jakewharton:butterknife-compiler:${versions.butterknife}"
annotationProcessor "com.jakewharton:butterknife-compiler:${versions.butterknife}"
//circle indicator
implementation 'me.relex:circleindicator:1.2.2#aar'
//glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation "com.android.support:design:${versions.design}"
implementation "com.android.support:design:${versions.appcompat_v7}"
//pdf shockwave
compile 'com.github.barteksc:pdfium-android:1.9.0'
//cat loader
implementation 'com.roger.catloadinglibrary:catloadinglibrary:1.0.4'
//shimmer text
compile 'com.romainpiel.shimmer:library:1.4.0#aar'
/*End here */
// compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2")
implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
implementation 'com.google.firebase:firebase-ml-vision-face-model:17.0.2'
implementation 'com.google.firebase:firebase-ml-model-interpreter:16.2.3'
implementation 'com.android.support:exifinterface:28.0.0'
Your project includes too many dependencies, try remove them one by one and gradle sync until you find which one caused error.
Its a time consuming task, but should do if you can not ensure.
And you could try add this in build.gradle----android:
dexOptions {
javaMaxHeapSize "4g" //enlarge heap size value.
}

Android Picasso different errors

I am trying to get image from web and put it into ImageView, but Picasso keeps showing errors.. when I refresh androidStudio, it shows another errors..
I looked up for solutions, but there is no relevant up-to-date post anywhere.
If anyone has any idea how to solve it, please comment.
Error: Program type already present: com.squareup.picasso.Action
Error: Program type already present:
com.squareup.picasso.Callback$EmptyCallback
Dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-
layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.picasso:picasso:2.5.2'
}
Picasso:
Picasso.with(About.this).load(photo).into(myImageView, new Callback() {
#Override public void onSuccess() {
Log.d("Debug", "Picasso Success");
}
#Override public void onError() {
Log.d("Debug", "Picasso Errored");
}
});
String photo:
String photo = getIntent().getExtras().getString("photo");
try to update to implementation "com.squareup.picasso:picasso:2.71828"
the duplicate entry program type already present can only come from another library or another module. most likely, there is a unnecessary picasso .jar in the libs directory, which ot delete.

Setting up Roboelectric testing for android

I am trying to add some Roboelectric unit tests to my app.
Using Roboelectric 3.0 i want to be able to test my activity PinActivity and the fragment that is in it.
import android.support.v7.app.AppCompatActivity;
import android.app.Fragment;
PinActivity extends AppCompatActivity {
gradle file contains:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0"
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
PinActivityTest contains: (Edited to add #Config did not fix)
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.*;
#RunWith(RobolectricTestRunner.class)
#Config(constants = BuildConfig.class, sdk = 21)
public class PinActivityTest {
#Test
public void onCreate_shouldInflateLayout() throws Exception {
PinActivity activity = Robolectric.buildActivity(PinActivity.class).create().get();
assertNotNull(activity);
}
Currently getting:
WARNING: No manifest file found at .\AndroidManifest.xml.Falling back to the Android OS resources only. To remove this warning, annotate your test class with #Config(manifest=Config.NONE). and java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Why can't it find my AndroidManifest?
Anyone know how i can fix this or more Roboelectric tutorials with similar examples?
As log says, you forgot about #Config annotation, so it could not find your AndroidManifest file:
Try this:
#RunWith(RobolectricGradleTestRunner.class)
#Config(constants = BuildConfig.class, sdk = 21) public class PinActivityTest {
#Test
public void onCreate_shouldInflateLayout() throws Exception {
PinActivity activity = Robolectric.buildActivity(PinActivity.class).create().get();
assertNotNull(activity);
}
As Roboelectric not support already API23, I set up test sdk as API 21.
EDIT: Change also:
PinActivity activity = Robolectric.buildActivity(PinActivity.class).create().get()
to
PinActivity activity = Robolectric.setupActivity(PinActivity.class);
NOTE: My Robolectric dependencies looks now:
testCompile("org.robolectric:robolectric:3.0") {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
If you have any question, please free to ask.
Hope it help

Categories

Resources