Dagger2 annotation processor is not working - android

I try to use Dagger2 in my Android project;
When I use apt, every things is right.But apt is not supported in AndroidStudio 3.0, so I use annotation processor.But no Dagger2 code created after I click "Make Project";
And I'm sure the annotetion processing is enable in AndroidStudio,because the Butterknife annotation processor is all right.
the follow is the build.gradle:
dependencies {
annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'
compile 'com.google.dagger:dagger-android:2.13'
compile 'com.google.dagger:dagger-android-support:2.13'
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}

use this in android studio 3.0 version
implementation 'com.google.dagger:dagger:2.9'
annotationProcessor 'com.google.dagger:dagger-compiler:2.9'

these are the dependences for dagger2 and butter in andriod studio 3.0
//ButterKniffe
compile "com.jakewharton:butterknife:8.8.1"
kapt "com.jakewharton:butterknife-compiler:8.8.1"
//dagger
compile "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"

It is one of the breaking changes coming with gradle:3.0 that Google announced at IO17 gradle:3.0
the compile configuration is now deprecated and should be replaced by implementation or api
From the gradle docs :
Dependencies appearing in the api configurations will be transitively exposed to consumers of the library, and as such will appear on the compile classpath of consumers.
Dependencies found in the implementation configuration will, on the other hand, not be exposed to consumers, and therefore not leak into the consumers' compile classpath. This comes with several benefits:
List item dependencies do not leak into the compile classpath of consumers anymore, so you will never accidentally depend on a transitive dependency
faster compilation thanks to reduced classpath size
less recompilations when implementation dependencies change: consumers would not need to be recompiled
cleaner publishing: when used in conjunction with the new maven-publish plugin, Java libraries produce POM files that distinguish exactly between what is required to compile against the library and what is required to use the library at runtime (in other words, don't mix what is needed to compile the library itself and what is needed to compile against the library).
The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.

Related

Unresolved reference "Searcher"

Trying to integrate instant search in my Android app, but "Searcher" is unresolved.
I have the following dependencies currently, am I missing any?
implementation "com.algolia:algoliasearch-android:3.27.0"
implementation "com.algolia:algoliasearch-client-kotlin-jvm:1.0.0"
implementation 'com.algolia:instantsearch-androidx:1.15.2'
implementation "io.ktor:ktor-client-android:1.2.2"
include core dependency also
implementation 'com.algolia:instantsearch-androidx-core:1.15.2'
The latest release of instantsearch-androidx is lacking its transitive dependencies. The issue was reported on GitHub, you can follow its progress there - likely a new version will soon be released with the appropriate dependencies packaged.
As a workaround, you can add the dependencies yourself to your application - depending on the InstantSearch features you use, you might need some or all of the following:
implementation "com.algolia:instantsearch-androidx:$VERSION_INSTANTSEARCH"
implementation "com.algolia:instantsearch-androidx-core:$VERSION_INSTANTSEARCH"
implementation 'com.algolia:algoliasearch-android:3.27.0'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'

Error in Android Studio Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api' [duplicate]

I just update my android studio to 3.0 now, but when I try to build apk on my project, it's shows following error:
Project depends on com.google.android.support:wearable:2.0.0, so it must also depend (as a provided dependency) on com.google.android.wearable:wearable:2.0.0
My build.gradle is like that:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':lpd')
compile 'com.google.android.support:wearable:2.0.0-alpha2'
compile 'com.google.android.gms:play-services-wearable:9.4.0'
compile files('libs/zxing_2.3.0.jar')
compile(name: 'hwwearableservice-release', ext: 'aar')
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
}
Anything wrong with it?
As per the new gradle dependency instruction the compile has been deprecated so for libraries use api and use the latest stable lib version as 2.1.0
and since the version is a stable release so
api 'com.google.android.support:wearable:2.1.0'
or it's better to use
implementation 'com.google.android.support:wearable:2.1.0'
implementation
if an implementation dependency changes its API, Gradle recompiles
only that dependency and the modules that directly depend on it. Most
app and test modules should use this configuration.
api
When a module includes an api dependency, it's letting Gradle know
that the module wants to transitively export that dependency to other
modules, so that it's available to them at both runtime and compile
time. This configuration behaves just like compile (which is now
deprecated), and you should typically use this only in library
modules. That's because, if an api dependency changes its external
API, Gradle recompiles all modules that have access to that dependency
at compile time

Android studio 3.0 error, how can I get rid of it?

I just update my android studio to 3.0 now, but when I try to build apk on my project, it's shows following error:
Project depends on com.google.android.support:wearable:2.0.0, so it must also depend (as a provided dependency) on com.google.android.wearable:wearable:2.0.0
My build.gradle is like that:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':lpd')
compile 'com.google.android.support:wearable:2.0.0-alpha2'
compile 'com.google.android.gms:play-services-wearable:9.4.0'
compile files('libs/zxing_2.3.0.jar')
compile(name: 'hwwearableservice-release', ext: 'aar')
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
}
Anything wrong with it?
As per the new gradle dependency instruction the compile has been deprecated so for libraries use api and use the latest stable lib version as 2.1.0
and since the version is a stable release so
api 'com.google.android.support:wearable:2.1.0'
or it's better to use
implementation 'com.google.android.support:wearable:2.1.0'
implementation
if an implementation dependency changes its API, Gradle recompiles
only that dependency and the modules that directly depend on it. Most
app and test modules should use this configuration.
api
When a module includes an api dependency, it's letting Gradle know
that the module wants to transitively export that dependency to other
modules, so that it's available to them at both runtime and compile
time. This configuration behaves just like compile (which is now
deprecated), and you should typically use this only in library
modules. That's because, if an api dependency changes its external
API, Gradle recompiles all modules that have access to that dependency
at compile time

How Do I Resolve android.arch.lifecycle:common Version Conflicts?

Given a project with this set of dependencies:
dependencies {
compile "com.android.support:recyclerview-v7:26.1.0"
compile "com.android.support:support-core-utils:26.1.0"
compile "com.android.support:support-fragment:26.1.0"
compile 'io.reactivex.rxjava2:rxjava:2.1.3'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'android.arch.lifecycle:runtime:1.0.0'
compile 'android.arch.lifecycle:extensions:1.0.0-beta2'
compile 'android.arch.lifecycle:reactivestreams:1.0.0-beta2'
compile "android.arch.persistence.room:runtime:1.0.0-beta2"
compile "android.arch.persistence.room:rxjava2:1.0.0-beta2"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-beta2"
androidTestCompile "com.android.support:support-annotations:26.1.0"
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'android.arch.core:core-testing:1.0.0-beta2'
androidTestCompile "com.android.support:support-core-utils:26.1.0"
androidTestCompile "com.android.support:support-compat:26.1.0"
}
I am getting the following error:
Error:Conflict with dependency 'android.arch.lifecycle:common' in project ':app'. Resolved versions for app (1.0.2) and test app (1.0.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
How do I resolve this?
Artifact dependency inconsistencies are a common problem, and I expect this to be a frequent issue with the Architecture Components, given that the versioning of those components is byzantine1.
In this case, there is an undocumented version 1.0.2 of the undocumented android.arch.lifecycle:common artifact.
android.arch.lifecycle:extensions:1.0.0-beta2 and android.arch.lifecycle:reactivestreams:1.0.0-beta2 depend upon this undocumented version 1.0.2 of the undocumented android.arch.lifecycle:common artifact. However, the corresponding test artifact (android.arch.core:core-testing:1.0.0-beta2) depends on version 1.0.0 of android.arch.lifecycle:common. As a result, we get the conflict.
The workaround is to manually request 1.0.2 for the test code, via:
androidTestCompile 'android.arch.lifecycle:common:1.0.2'
Gradle will now use 1.0.2 for both the main code and the test code, and all is well.
1 The term "byzantine" is used to describe something that is unnecessarily complex. The Byzantines might have described complex things with the phrase "like the versioning system of the Architecture Components", had those components existed back then.

Android Gradle Implementation vs CompileOnly Performance

The docs mention that implementation provides significant build time improvements over compile/api. What about compileOnly?
My use case is a multi-module (sorry I don't like Gradle's multi-project terminology) project, where I have an Android app, and multiple libraries that the app depends on (implementation). Some of the libraries also depend on one another. Should I use implementation or compileOnly when declaring dependencies in the library modules? My app module will be using implementation to depend on those artifacts, so I don't need them to be transitive through the library modules.
The api configuration should be used for dependencies that are exported to external modules (transitive dependency). Vice-Versa implementation configuration should be used for dependencies that are internal to the component (not transitive dependency).
implementation vs compileOnly:
There is no similarity in their job, compileOnly is
a configuration inherited from java-plugin
required at compile time
also not included in the runtime classpath or exposed to dependent
projects.
So compileOnly doesn't replace the implementation configuration job e.g:
implementation 'com.android.support:appcompat-v7:25.1.0' // can't use compileOnly here
testCompile 'junit:junit:4.12'
compile "com.google.dagger:dagger:2.8" // can't use here also
annotationProcessor "com.google.dagger:dagger-compiler:2.8" // can't use here also
compileOnly 'javax.annotation:jsr250-api:1.0' // we can use compileOnly here because it's required on run time only.
Since your case is a "multi-module", you have to use the api configuration, until you reach the final module it's better to use implementation.
Following graph describe those configurations:
Performance?
I think api requires more memory because gradle will snapshot every class in that transitive module, vice versa implementation is a preferred configuration because (as mentioned above) it's used for its own internal implementations.

Categories

Resources