Comments (11)
For me it works when adding dagger 2 with both apt and testCompile scopes.
BTW, it would be great if we could have an example of testing with Dagger 2. It's not obvious at all to figure out how module can be overiden.
from dagger.
Can you please provide an example project? I tried to add dagger compiler as a testCompile dependency but without success.
from dagger.
I'm also running into this issue. An example project or a few pointers would be helpful. Thanks!
from dagger.
That build.gradle
script works for me (with android apt plugin):
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
// Additional for unit tests
testProvided 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
}
from dagger.
Can you please provide an example project? I would like to see the whole project configuration related to JUnit tests.
from dagger.
Our recommendation for Android Studio is to use https://bitbucket.org/hvisser/android-apt as described above. I'm going to close this. If you are still encountering it when using the apt plugin, and after updating all dependencies, please re-open this, but point to either a github repo with an example project, or a gist containing a failing test, or something so we can reproduce this.
from dagger.
Here is the AndroidStudio example project: https://github.com/westward/Dagger2Test
It contains the single JUnit file named DummyControllerTest.java with code that should create a Component. I tried "testProvided", "testCompile" directives in build.gradle, both variants without success.
Thanks!
P.S. Christian, I cannot re-open my issue. Please do it by yourself if it's possible.
from dagger.
@cgruber why use android apt plugin ? Gradle and Android Studio are supposed to have annotation processor support out of the box, no ?
from dagger.
@stephanenicolas javac
does annotation processing out of the box (unless told otherwise) by looking for processors in the classpath. So in that sense, yes, Gradle supports annotation processing out of the box. But Gradle is missing one thing: dependencies that you need when compiling but not at runtime (such as annotation processors; you don't want to package them into your application). Additionally, ideally, you'd want to be explicit about your processorpath, rather than just put annotation processors in the classpath: the processorpath is usually much smaller than the classpath so processor discovery is faster, but more importantly you know you're not bringing in an annotation processor that you didn't mean to use (for example, antlr' includes its own annotation processor: antlr/antlr4#487)
So you want an apt
(or whatever its name) configuration
that ends up filling javac
's -processorpath
, independently of the classpath. android-apt
does just that, for Android builds.
from dagger.
And it also makes the generated sources visible to the IDE automatically.
from dagger.
OK guys, what's wrong with my example project? What I've missing? I can't use Dagger2 in tests, I didn't configured project well, something else? Any advice or hint please!
from dagger.
Related Issues (20)
- Optional bindings in a parent component can sometimes use bindings from child components HOT 2
- NullPointerException dagger.spi.shaded.androidx.room.compiler.processing.XTypeElement.getAnnotation HOT 6
- Problem with Injection of DAO HOT 1
- error: [Hilt] Could not get element for com.foo.viewModels.FooViewModel_HiltModules.BindsModule: java.lang.NullPointerException HOT 1
- Missing release notes for 2.51 HOT 1
- `LazyClassKey` doesn't work when providing a `Map<Class<*>, Provider<?>` with a scope
- @AssistedInject in ViewModel using Dagger (NOT Hilt, just dagger) does not compile: cannot be provided without an @Inject constructor or an @Provides-annotated method HOT 6
- [issue] Dagger doesn't compile or doesn't give a right error message when ViewModelFactory is implemened on Kotlin rather than on Java HOT 4
- Having an issue with Dagger Hilt Proguard Rules HOT 12
- Following dagger.dev tutorial doesnt create singleton in v2.51 HOT 2
- Multibinding with Nested Complex Keys uses the wrong AnnotationCreator HOT 1
- [Hilt] onCreate() in my Application doesn't called on Instrument test HOT 4
- [Dagger-Hilt] Error when applying obfuscation other than Proguard (Allatori) HOT 3
- error: [Hilt] Expected @AndroidEntryPoint to have a value HOT 3
- @IntoSet analog for injectable classes HOT 3
- Hilt Generated Code having not used code? HOT 2
- [Dagger-Hilt] Can't get viewModel in composable by Hilt HOT 1
- Why does Provides in a Companion Object work? HOT 5
- Update Dagger guava dependency to address CVE-2023-2976 HOT 2
- Add KMP support for @HiltViewModel annotation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.