DaggerApplicationComponent not generated in my code? - java

DaggerApplicationComponent is not generated in my code, I am learning Dagger for android and facing this issue. Below my project files.
https://github.com/SK010101/AdvanceAndroidTutorial
// component = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
this thing not generated.
I have tried all clean and rebuild project.
Also tried Invalidate Caches/Restart.
Please help anyone))

inside dependencies block, add these lines:
api 'com.google.dagger:dagger:2.24'
api 'com.google.dagger:dagger-android:2.24'
api 'com.google.dagger:dagger-android-support:2.24'
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
kapt 'com.google.dagger:dagger-compiler:2.24'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.24'
kapt 'com.google.dagger:dagger-android-processor:2.24'
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'
Inside android block of build.gradle,
kapt {
generateStubs = true
}
At the top of the build.gradle, Do this in exactly below order.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
Finally, You need to enable "Annotation processor" from File>Other Settings>Settings for New Projects>search"Annotation processor"
After this, do from Menu Build > Rebuild. Done!

My Bug solved after Build run on emulator))

Related

Appcompat activity along with androidx gradle version issue in android studio

Appcompat version used in app is v7, androidx is used for integration with gradle.properties for firebase connection
Please help
You are using the wrong build.gradle file
You have to move the implementation from the top-level file to the app/build.gradle file in the dependencies block (not the dependencies in the buildscript block)::
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
//...
}
dependencies {
//...
implementation 'androidx.xxxxx'
}

Failed to apply plugin "com.google.gms.google-services"

Here is my project build.gradle:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.1.0'
}
}
In one of the module's build.gradle I have this:
apply plugin: 'com.google.gms.google-services'
which results into the following error:
Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension.
Fun fact, if I set google-services version to 3.0.0, this specific error disappears, but Gradle asks me to downgrade versions of other google libraries, but I really do not want to do that.
How do I deal with these LibraryVariants?
You only set apply plugin: 'com.google.gms.google-services' in the app module, and in no other modules.
You must add one dependencies in your build.gradle(Project:project_name)
classpath 'com.google.gms:google-services:3.1.0'
And add in your build.gradle(build.gradle:Module app)
apply plugin: 'com.google.gms.google-services'
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
}
apply plugin: 'com.google.gms.google-services'

android push notifications library with google cloud messaging

i am working on an android using GCM application and adding support libraries,i added the following to my gradle
i added a plugin
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
and dependencies: i added:
compile 'com.google.android.gms:play-services:8.3.0'
classpath 'com.google.gms:google-services:3.0.0'
but it brings an error
Error:(3, 0) Plugin with id 'com.google.gms.google-services' not found.
and yet i see the plugin added. how to i correct it thank you
In your project level build.gradle add like following:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
While your App level build.gradle should look like this:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.google.android.gms:play-services-gcm:8.3.0"
}
apply plugin: 'com.google.gms.google-services'
Make sure to add apply plugin: 'com.google.gms.google-services' as last line in your app level gradle file.
You should only apply the com.android.application plugin.
Applying the java plugin as well will result in a build error.
Reference : http://tools.android.com/tech-docs/new-build-system/user-guide
The dependencies you have added are fine. You can remove the "apply plugin: 'com.google.gms.google-services'" entry.

Apt for Java subproject

I am developing an Android project. I have a plain java subproject. I would like to activate the apt process for this java subproject. My gradle file:
project(':subproject') {
apply plugin: 'java'
apply plugin: 'android-apt'
dependencies {
compile files('../app/libs/sqliteannotations-api-0.1-SNAPSHOT.jar')
apt files('../app/libs_annotations/sqliteannotations-0.1-SNAPSHOT-jar-with-dependencies.jar')
}
}
but I get this error:
The android or android-library plugin must be applied to the project
Add apply plugin: 'com.android.application' if you are working on an app.
Add apply plugin: 'com.android.library' if you are working on a library.

How to import android project as library and NOT compile it as apk (Android studio 1.0)

I tried to import a project(projLib) as dependency for another project(projAPK).
projAPK gradle has this :
dependencies {
compile project(':libs:NewsAPI')
compile project(':projLib')
}
but when i sync the gradle it gives this error:
Error:Dependency Android_2015:projLib:unspecified on project projAPK resolves to an APK archive which is not supported as a compilation dependency. File: /Users/myname/Documents/Development/Android_2015/libs/projAPK/build/outputs/apk/projLib-release-unsigned.apk
so I guess there are two solution to this:
somehow make gradle think that projLib is a library that shouldn't be compiled to apk
somehow make gradle NOT compile the projLib explicitly
The problem is, I couldn't find how to do any of that.
Would be awesome if you guys can help :)
In projLib's build.gradle file, you'll see a statement like this:
apply plugin: 'com.android.application'
which tells Gradle to build it as an application, generating an APK. If you change it to this:
apply plugin: 'com.android.library'
it will build as a library, generating an AAR, and it should work.
If you also need projLib to generate a separate APK, then you'll have to do some refactoring to pull the common code that you need out into a third library module, and have both APKs depend on it.
Libraries aren't allowed to set an applicationId, so if you see an error message to that effect, remove it from the library's build script.
In module gradle file-
Replace apply plugin: 'com.android.application' with apply plugin: 'com.android.library'
Then remove applicationId "xxx.xxx.xxxx"
Clean and Build
just add these lines to library gradle file and remove other sections
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:gridlayout-v7:23.1.1'
,...
}
For Kotlin DSL (build.gradle.kts), use this notation:
plugins {
id("com.android.library")
// ...
}

Categories