I have been trying to include Dagger latest version dagger-android:2.11 in my app. But, Daggerclaases like DaggerAppComponent is not being generated.
following is my app level gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "net.maskery.android.lab.lawyerapp"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
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:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.google.dagger:dagger-android:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
}
my component interface
#Component(modules = {AppModule.class})
public interface AppComponent {
void inject(MainActivity mainActivity);
}
my module class
#Module
public class AppModule {
private LawyerApp app;
public AppModule(LawyerApp app) {
this.app = app;
}
#Provides public Context providesContext(){
return app;
}
#Provides public Resources providesResources(){
return app.getResources();
}
}
the app is properly building but when am trying to create AppComponent object, DaggerAppComponent is just not availbale.
I have enabled annotation processing in the settings and created this app only after that.
I tried 'com.neenbedankt.android-apt' plugin too,. This also didnt work for me.
This is like hit-end for me over any options to try here. Please help.
Related
I need to remove ACRA for removing any vulnerabilities.
I had removed all imports/compiles in app.gradle and MyApplication.java. However, when I tried to build the project, the IDE gives below error:
error: cannot find symbol class RequiresApi
These are my app.gradle and MyApplication.java
app.gradle (I could not build after I removed compile 'ch.acra:acra:4.9.2' in dependencies)
buildscript {
(omitted)
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "******"
minSdkVersion 17
targetSdkVersion 22
versionCode 6
versionName "1.0.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable 'RestrictedApi'
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.journeyapps:zxing-android-embedded:3.0.1#aar'
compile 'com.google.zxing:core:3.2.0'
compile 'com.jakewharton:butterknife:8.0.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'
compile 'net.zetetic:android-database-sqlcipher:3.5.7#aar'
compile 'com.google.code.gson:gson:2.8.2'
//compile 'ch.acra:acra:4.9.2' <- REMOVED ACRA
compile "io.reactivex.rxjava2:rxjava:2.1.9"
compile "io.reactivex.rxjava2:rxandroid:2.0.2"
}
MyApplication.java
package ******;
import android.app.Application;
public class MyApplication extends Application {
private static MyApplication myApplication;
public static MyApplication getInstance() {
return myApplication;
}
public void onCreate() {
super.onCreate();
myApplication = this;
}
}
I had also tried cleaning my project and rebuild, but did not work. When I put ACRA back, the project builds as usual. Is it the problem of IDE?
#RequiresApi is part of com.android.support:support-annotations. You have to add that as a dependency
e.g.
dependencies {
com.android.support:support-annotations:27.1.1
}
I am getting error
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I added linked in sdk successfully but when I compile project(':linkedin-sdk') then give me error i tried to resolve this error i also try multiDexEnabled true but still get error this is my app.gradle file
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'http://developers.quikkly.io/nexus/repository/maven-releases/' }
maven { url 'http://developers.quikkly.io/nexus/repository/maven-snapshots/' }
maven { url 'https://maven.fabric.io/public' }
mavenLocal()
}
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.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.27.0'
compile 'com.intuit.sdp:sdp-android:1.0.4'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
compile 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
compile 'com.brucetoo.pickview:library:1.2.3'
compile 'com.caverock:androidsvg:1.2.1'
compile 'commons-io:commons-io:2.5'
// Pretty color picker
compile('com.thebluealliance:spectrum:0.7.1') {
// spectrum uses older support libs, override these with latest.
exclude group: 'com.android.support'
}
compile('net.quikkly.android:quikklycore-lib:1.2.0#aar') {
transitive = true
}
compile 'net.quikkly.android:quikkly-lib:1.2.0#aar'
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
// Include all the Twitter APIs
compile 'com.twitter.sdk.android:twitter:3.1.1'
// (Optional) Monetize using mopub
compile 'com.twitter.sdk.android:twitter-mopub:3.1.1'
implementation 'com.android.support:support-v13:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-vector-drawable:26.1.0'
}
this is my linkedin gradle file
allprojects {
repositories {
mavenCentral()
}
}
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'android-library'
android {
sourceSets {
androidTest {
setRoot('src/test')
}
}
compileSdkVersion 17
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
configurations {
}
dependencies {
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:21.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/volley.jar')
androidTestCompile('junit:junit:4.12')
}
I used android studio 3.0 RC 2 with cannery if any kind of help or suggestion please let me know thank in advances
EDIT:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Use this in your linkedin gradle file:
allprojects
{
repositories
{
maven
{
url "https://maven.google.com"
}
}
}
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
public class ApplicationClass extends MultiDexApplication {
#Override
public void onCreate() {
super.onCreate();
}
}
I am putting up the complete MultidexApplication code
app gradle
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Caution: Do not execute MultiDex.install() or any other code through reflection or JNI before MultiDex.install() is complete. Multidex tracing will not follow those calls, causing ClassNotFoundException or verify errors due to a bad class partition between DEX files.
I am creating an application class to use Firebase in my complete application. However in the import line error occurs highlighting 'firebase' in red.
I have looked everywhere but cannot make out the problem.
Code:
package com.mobility.mobilityindia;
import android.app.Application;
import com.firebase.client.Firebase; <--- firebase is red here
public class MobilityIndia2 extends Application{
#Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this); <---- Firebase is red here
}
app level gradle.build
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig
{
applicationId "com.mobility.mobilityindia"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
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'
})
String googleSupportVersion = '26.+'
String googlePlayServicesVersion = '11.0.2'
compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
compile "com.google.firebase:firebase-auth:$googlePlayServicesVersion"
compile "com.android.support:appcompat-v7:$googleSupportVersion"
compile "com.android.support:support-v4:$googleSupportVersion"
compile "com.google.android.gms:play-services:$googlePlayServicesVersion"
compile "com.android.support:design:$googleSupportVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
apply plugin: 'com.google.gms.google-services'
top level gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
}
}
The code you have is for an old version of the Firebase SDK (1.x or 2.x), while you're importing the latest version.
If you follow the latest documentation or the latest Android codelab, you won't need the Firebase.setAndroidContext() anymore and will get imports that start with com.google.firebase.
after many hours getting headaches... i'm resigned to ask you guys ^^
got two simple Dagger 2 components but both of them doesn't compile. But sometimes (i don't understand why) it does ...
this is really annoying.
So i think i should miss something, here is the error :
Error:(18, 17) error: ....InstanceContextService cannot be provided without an #Provides- or #Produces-annotated method.
home.HomeActivity.mInstanceContextService
[injected field of type: ....services.InstanceContextService mInstanceContextService]
So my compoments is like this :
#Component(modules = {InstanceContextModule.class})
#Singleton
public interface InstanceContextComponent {
#Singleton
void inject(HomeActivity activity);
}
My module :
#Module
public class InstanceContextModule {
#Provides
#Singleton
public InstanceContextService provideInstanceContext() {
return new FileInstanceService();
}
}
and my config in gradle is
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
// compileOptions.incremental = false
defaultConfig {
applicationId "com.kayentis.ediary"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
res.srcDirs = [
'src/main/res',
'src/main/res-main',
'src/main/res-message',
'src/main/res-account'
]
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v13:23.1.+'
compile 'com.google.code.gson:gson:2.1'
//compile 'com.google.protobuf:protobuf-java:2.6.1'
//Dagger 2
// apt 'com.google.dagger:dagger-compiler:2.3'
// compile 'com.google.dagger:dagger:2.3'
apt 'com.google.dagger:dagger-compiler:2.0.2'
compile 'com.google.dagger:dagger:2.0.2'
provided 'org.glassfish:javax.annotation:10.0-b28'
//Retrofit 2.0
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
//RxJava
compile 'io.reactivex:rxjava:1.1.0'
compile 'io.reactivex:rxandroid:1.1.0'
//ButterKnife
// compile 'com.jakewharton:butterknife:7.0.1'
}
I'm looking everywhere but i think i miss something...
Thanks in advance ^^
Found the Solution.
Had two component with #singleton scoped modules, so this can't work. Now it's building successfull.
I'm having trouble running tests in Android Studio. I've read through a load of posts with the same problem here on Stack Overflow, but to no avail. Just to be clear, I want to test in the emulator and not in the JVM.
Run configuration:
Output:
Running tests
Test running startedTest running failed: No test results
Empty test suite.
Build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "ntnu.stud.markul.crowdshelf"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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.0.1'
// Unit testing dependencies
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.3') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
The test class (located in /src/androidTest/java/com/appname/app/):
#RunWith(AndroidJUnit4.class)
public class NetworkAndDBInstrumentationTest extends ActivityInstrumentationTestCase2<MainActivity> {
private MainActivity mActivity;
public NetworkAndDBInstrumentationTest() {
super(MainActivity.class);
}
#Before
public void setUp() throws Exception {
super.setUp();
// Injecting the Instrumentation instance is required
// for your test to run with AndroidJUnitRunner.
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
#Test
public void typeOperandsAndPerformAddOperation() {
NetworkController.getCrowd("55f01f29f0a5fad2120bb1db");
System.out.print("ok");
Log.d("1TEST", "1TEST");
}
#After
public void tearDown() throws Exception {
super.tearDown();
}
}
I got it to work using this:
#RunWith(AndroidJUnit4.class)
#LargeTest
public class NetworkAndDBInstrumentationTest {
//use the following annotation and declare an ActivityTestRule for your activity under test
#Rule
public ActivityTestRule<RealmActivity> mActivityRule = new ActivityTestRule(RealmActivity.class);
//use #Before to setup your test fixture
#Before
public void setUp() { }
//annotate all test methods with
#Test
public void testGetCrowd() {
Assert.assertEquals(1, 1);
}
#After
public void tearDown() { }
}
Where RealmActivity is the Activity I want to test. Build.gradle and everything else is as in the question post. Now, a follow-up question: What does it matter that I make the #Rule with RealmActivity? Can't I use other Activities in that test? Can I make a Activity-independent test?
Your configuration looks right. You can try to add this to your build.gradle file:
/*
* Working build.gradle test config. Gradle version 1.3.0
*/
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "test.your.app"
minSdkVersion 15
targetSdkVersion 23
versionCode versionMajor * 100 + versionMinor * 10 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
}
configurations.all {
// Currently espresso is dependent on support-annotations:22.2.1
resolutionStrategy.force 'com.android.support:support-annotations:22.2.1'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
disable 'SetJavaScriptEnabled'
disable 'InvalidPackage'
abortOnError false
textReport true
textOutput 'stdout'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
applicationIdSuffix '.debug'
testCoverageEnabled = true
}
release {
}
}
productFlavors {
dev {
versionName "DEV"
}
}
sourceSets { //this one may not be needed. But wont hurt.
androidTest.setRoot('src/androidTest')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Android
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:support-v13:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-annotations:23.0.1'
// Google Play Services
compile 'com.google.android.gms:play-services-base:7.8.0'
compile 'com.google.android.gms:play-services-analytics:7.8.0'
compile 'com.google.android.gms:play-services-appindexing:7.8.0'
// Integration Tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude group:'com.android.support', module:'support-v4'
exclude module: 'recyclerview-v7'
}
// Unit Tests
testCompile 'junit:junit:4.12'
testCompile 'com.google.truth:truth:0.25'
//Mocking
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile "com.google.dexmaker:dexmaker:${DEXMAKER_VERSION}"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:${DEXMAKER_VERSION}"
androidTestApt "com.google.dagger:dagger-compiler:${DAGGER_VERSION}"
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test:runner:0.3'
// Leak detection
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
}
You could also try using JUnit 3 style to see if that gets better results. Are you extending ApplicationTestCase? Try and get things working there.
I think you need add this line in your dependencies:
androidTestCompile ('org.hamcrest:hamcrest-library:1.3')