why does dagger 2 generated components gets deleted on project rebuild? - android

The problem exists when the code that uses the generated 'Dagger' prefixed on a component is not commented out. If it was commented out, the generated Dagger 2 files are generated.
BookModule
#Module
public class BookModule {
#Provides
public Book providesBook(){
return new Book();
}
}
BookComponent
#Component(modules = BookModule.class)
public interface BookComponent {
void inject(MainActivity activity);
public Book getBook();
}
MainApplication
public class MainApplication extends Application {
public static BookComponent mBookComponent;
#Override
public void onCreate() {
super.onCreate();
mBookComponent = DaggerBookComponent.builder().bookModule(new BookModule()).build();
}
}
Build.gradle(Application)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build.gradle(Project)
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.bryan.myapplication"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions{
enabled = true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:support-v4:24.2.0'
compile group: 'com.google.dagger', name: 'dagger', version: '2.10-rc1'
apt group: 'com.google.dagger', name: 'dagger-compiler', version: '2.10-rc1'
compile group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3'
}
Error Stacktrace
ERROR: C:\bin\AndroidProjects\MyApplication\app\src\main\java\com\example\lloyd\myapplication\MainApplication.java:12.26: DaggerBookComponent cannot be resolved
com.android.jack.api.v01.CompilationException: Failed to compile
at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:144)
at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackApis(AndroidBuilder.java:1931)
at com.android.build.gradle.tasks.JackTask.doMinification(JackTask.java:148)
at com.android.build.gradle.tasks.JackTask.access$000(JackTask.java:73)
at com.android.build.gradle.tasks.JackTask$1.run(JackTask.java:112)
at com.android.builder.tasks.Job.runTask(Job.java:51)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:223)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.jack.frontend.FrontendCompilationException: Failed to compile
at com.android.jack.Jack.buildSession(Jack.java:1053)
at com.android.jack.Jack.run(Jack.java:540)
at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:124)
... 8 more
mBookComponent = DaggerBookComponent.builder().bookModule(new BookModule()).build();
The code from above is in the MainApplication and it is the problem, if I commented it out, it rebuilds completely fine. But when I left it as it is, it got an error saying the 'DaggerBookComponent' cannot be resolved, by this time the generated DaggerBookComponent is deleted which results in cannot be resolved

When you do a rebuild, the build system looks at the Dagger module and component classes and generates the actual classes that make all of dagger work. When you do a normal incremental build, it doesn't (it assumes the old versions are still good). This means when you rebuild if there's some error in your program or in your dagger components/modules it will not be able to rebuild these files.
So basically, you have a bug somewhere, likely (although not necessarily) in your dagger setup. When you fix it, you'll stop having problems.

Related

Failed to resolve in gradle, Unsplash photo picker android studio

I am trying to implement Unsplash API according to this website:
https://unsplash.com/documentation#creating-a-developer-account
But got stuck pretty quickly. I don't know why Gradle refuses to compile so here are some files:
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
maven { url 'https://jitpack.io' }
}
dependencies {
def nav_version = "2.5.2"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (App)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
id "kotlin-parcelize"
}
android {
compileSdk 33
defaultConfig {
applicationId "com.example.gallery"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.example.gallery'
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
// Unsplash
implementation 'com.github.unsplash:unsplash-photopicker-android:1.0.1'
// Kotlin
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
// tests
testImplementation "com.google.truth:truth:1.1.3"
testImplementation "android.arch.core:core-testing:1.1.1"
testImplementation 'org.robolectric:robolectric:4.8'
}
All I try to do is to add those lines (from the GitHub specification):
To integrate UnsplashPhotoPicker into your Android Studio project
using Gradle, specify in your project build.gradle file:
allprojects { repositories {
...
maven { url 'https://jitpack.io' } } } And in your app module build.gradle file, replacing x.y.x by the latest tag:
dependencies { implementation
'com.github.unsplash:unsplash-photopicker-android:x.y.z' }
The problem occured(8 similar problem):
Execution failed for task ':gallery:desugarDebugFileDependencies'.
Could not resolve all files for configuration ':gallery:debugRuntimeClasspath'.
Could not find com.github.unsplash:unsplash-photopicker-android:1.0.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
- https://repo.maven.apache.org/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
Required by:
project :gallery
This question was asked Here but got no answer...
Add the
maven { url 'https://jitpack.io' }
in setting.gradle(project level)
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
//...
maven { url 'https://jitpack.io' }
}
}

Error in supressing #InstallIn check whilst migrating from Dagger to Hilt using flag -Adagger.hilt.disableModulesHaveInstallInCheck=true

I have been recently trying to migrate my Android App from Dagger to Hilt.
I would like to carry out the entire migration in phases and hence was trying to suppress the Hilt warning for not using #InstallIn for modules.
Have been following the migration guide given here: https://dagger.dev/hilt/migration-guide.html
Also found the flag which disables the #InstallIn check here: https://dagger.dev/hilt/compiler-options.html#disable-install-in-check
However, I have been struggling to get this flag to work.
To understand the issue better, I tried to migrate the Dagger Codelab (https://codelabs.developers.google.com/codelabs/android-dagger/#0) to Hilt.
Didn't find success even there.
Could someone please point out the error? I have attached the build.gradle files and the errors generated below.
Project Level build.gradle file
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App Level build.grade file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.android.dagger"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.example.android.dagger.MyCustomTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
String sharedTestDir = 'src/sharedTest/java'
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
tasks.withType(JavaCompile) {
configure(options) {
options.compilerArgs << "-Adagger.hilt.disableModulesHaveInstallInCheck=true"
}
}
}
dependencies {
def dagger_version = "2.27"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.core:core-ktx:1.2.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-livedata:2.2.0'
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:3.3.1'
testImplementation 'android.arch.core:core-testing:1.1.1'
def androidx_test_version = "1.2.0"
androidTestImplementation "androidx.test:runner:$androidx_test_version"
androidTestImplementation "androidx.test:core-ktx:$androidx_test_version"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
kaptAndroidTest "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
}
Generated warning and errors:
e: D:\androidLearn\dagger\android-dagger\app\build\tmp\kapt3\stubs\debug\com\example\android\dagger\di\AppSubcomponents.java:7: error: [Hilt]
public final class AppSubcomponents {
^
com.example.android.dagger.di.AppSubcomponents must also be annotated with #InstallIn.
[Hilt] Processing did not complete. See error above for details.
e: D:\androidLearn\dagger\android-dagger\app\build\tmp\kapt3\stubs\debug\com\example\android\dagger\di\StorageModule.java:7: error: [Hilt]
public abstract class StorageModule {
^
com.example.android.dagger.di.StorageModule must also be annotated with #InstallIn.
[Hilt] Processing did not complete. See error above for details.
w: warning: The following options were not recognized by any processor: '[dagger.hilt.android.internal.disableAndroidSuperclassValidation, kapt.kotlin.generated]'
You can add the compiler option to your app/build.gradle file in the android -> defaultConfig block like this:
android {
...
defaultConfig {
...
//TODO: remove this after migration to Hilt
javaCompileOptions.annotationProcessorOptions.arguments['dagger.hilt.disableModulesHaveInstallInCheck'] = 'true'
}
}
You can also add the same thing like below:
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments["dagger.hilt.disableModulesHaveInstallInCheck"]="true"
}
}
}

How to configure retrolambda for android6(API23)

I want to add Java8 support to my project. The only suitable solution I found is retrolambda gradle plugin project. Here is my build.gradle files for a project and module relatively.
Note: Please don't suggest migrate to Android Studio 3, because I want to understand why it is not working.
project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
module build.gradle
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.test.test"
minSdkVersion 15
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
retrolambda {
javaVersion JavaVersion.VERSION_1_7
defaultMethods true
}
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:26+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
The app itself is pretty simple. It has only one default activity, with Java8 code, like this:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> strings = new ArrayList<>();
strings.add("Hello");
strings.add("World");
strings.stream().forEach(System.out::println);
}
}
When start the app I get following an error:
FATAL EXCEPTION: main
Process: com.slesh.mtbbank, PID: 25338
java.lang.NoSuchMethodError: No interface method
stream()Ljava/util/stream/Stream; in class Ljava/util/List; or its
super classes (declaration of 'java.util.List' appears in
/system/framework/core-libart.jar)
at com.slesh.mtbbank.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6303)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2402)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2509)
at android.app.ActivityThread.access$1000(ActivityThread.java:153)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
What is missed? Any ideas why it doesn't work?
Thanks in advance!
strings.stream().forEach(System.out::println)
Retrolambda does only what its name suggests: it allows you to use lambdas. It does not support streams. There are libraries that backport stream API, but retrolambda does not.

Error in realm when using stripe payment method

i am integrating "Strip" payment method in my app but when i add the stripe dependence compile 'com.stripe:stripe-android:1.0.3' also try compile 'com.stripe:stripe-android:+' an error occur that is
i see many answer for realm Re-linker like using
compile 'com.getkeepsafe.relinker:relinker:1.2.1'
Compile 'io.reactivex:rxjava:1.1.0' but the problem is still exist
this is my Realm application class
public class WifiExploreApplication extends Application {
#Override
public void onCreate(){
super.onCreate();
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this)
.name("com.holygon.zaingz.alu").build();
Realm.setDefaultConfiguration(realmConfiguration)
}
}
this is my gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Apis:Google Apis:23'
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.wifiexplorer"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
multiDexEnabled true
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.github.sembozdemir:ViewPagerArrowIndicator:1.0.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.android.support:multidex:1.0.0'
compile "com.android.support:support-v4:23.0.0"
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.getkeepsafe.relinker:relinker:1.2.1'
compile 'com.stripe:stripe-android:1.0.3'
}
dependencies {
repositories {
mavenCentral()
}
compile 'com.sothree.slidinguppanel:library:3.3.0'
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
apply plugin: 'realm-android'
and
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath "io.realm:realm-gradle-plugin:0.88.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
before using stripe all the things going well but when i use strip it will show error
any suggestion will appreciate able..
You're using the AAR Gradle Plugin version of Realm (as in 0.88.0+, but an outdated one, considering the latest is 1.1.0) but you're never actually calling apply plugin: 'realm-android' in your build.gradle file.
You're also missing this from your application class
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Oh by the way, you probably should use modularized version of Google Play Services so that you wouldn't even need Multi-Dex in the first place.

BR cannot be resolved

I am not able to add notifyPropertyChanged(int itemId) because of certain issue in gradle, i guess!
any help would be well appreciated
public class RegisterForm extends BaseObservable {
#Bindable
public String firstName;
#Bindable
public int getFirstNameLabelVisibility(){
return TextUtils.isEmpty(firstName) ? View.INVISIBLE : View.VISIBLE;
}
public void setFirstNameFromView(String firstNameFromView) {
firstName = firstNameFromView;
// notifyPropertyChanged(BR.firstName); this line is giving error!
}
}
Build.gradle // for App
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
apply plugin: 'android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.jivrajsingh.databindingimp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
configurations {
apt
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
apt 'com.android.databinding:compiler:1.0-rc0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
}
Build.gradle // for project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.databinding:dataBinder:1.0-rc2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Thanks for your precious time :)
You have the old plugin setup with the new gradle version.
Remove the data binding plugin & its dependency from classpath.
Now it is integrated and all you need is
android {
dataBinding { enabled = true }
}
http://developer.android.com/tools/data-binding/guide.html

Categories

Resources