Dagger2 - ApplicationComponent not generated - android

I followed vogella article: http://www.vogella.com/tutorials/Dagger/article.html
I did everything step by step as they suggested. My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "test.daggertest"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.dagger:dagger:2.15'
implementation 'com.google.dagger:dagger-android:2.15'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.15'
annotationProcessor 'com.google.dagger:dagger-compiler:2.15'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
MyApplication class:
public class MyApplication extends Application implements HasActivityInjector
{
#Inject
DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
#Override
public void onCreate()
{
super.onCreate();
DaggerMyApplicationComponent.create().inject(this);
}
#Override
public DispatchingAndroidInjector<Activity> activityInjector()
{
return dispatchingAndroidInjector;
}
}
Then I did Rebuild project, and still it throws error DaggerMyApplicationComponent is unresolved.
Am I missing something or their article is outdated? Any ideas?

Related

I'm trying to build a Kotlin application, but I get the error "Dao class must be annotated with #Dao"

I am trying to build a Kotlin manga application through Android Studio, but I get an error like
I tried googling, but I could not find anything other than an article on SOF, if I understood correctly, this does not work for me
build.gradle(:app)
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-parcelize'
}
android {
compileSdkVersion 31
buildToolsVersion '30.0.3'
defaultConfig {
applicationId 'org.nkno.yumu'
minSdkVersion 21
targetSdkVersion 31
versionCode 374
versionName 'beta1'
generatedDensities = []
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
kapt {
arguments {
arg 'room.schemaLocation', "$projectDir/schemas".toString()
}
generateStubs = true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
debug {
applicationIdSuffix = '.debug'
}
release {
multiDexEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
testOptions {
unitTests.includeAndroidResources = true
unitTests.returnDefaultValues = false
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += [
'-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
]
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
implementation 'androidx.fragment:fragment-ktx:1.4.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-service:2.4.0'
implementation 'androidx.lifecycle:lifecycle-process:2.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.work:work-runtime-ktx:2.7.1'
implementation 'com.google.android.material:material:1.4.0'
//noinspection LifecycleAnnotationProcessorWithJava8
kapt 'androidx.lifecycle:lifecycle-compiler:2.4.0'
implementation 'androidx.room:room-runtime:2.3.0'
implementation 'androidx.room:room-ktx:2.3.0'
kapt 'androidx.room:room-compiler:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okio:okio:2.10.0'
implementation 'org.jsoup:jsoup:1.14.3'
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.1'
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.1'
implementation 'io.insert-koin:koin-android:3.1.4'
implementation 'io.coil-kt:coil-base:1.4.0'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
implementation 'com.github.solkin:disk-lru-cache:1.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.1.3'
testImplementation 'org.json:json:20210307'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.2'
testImplementation 'io.insert-koin:koin-test-junit4:3.1.4'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
androidTestImplementation 'androidx.room:room-testing:2.3.0'
androidTestImplementation 'com.google.truth:truth:1.1.3'
}
Sorry for the wrong formatting)
Full error message:
e: C:\Users\USER\Desktop\Yumu-manga\app\build\tmp\kapt3\stubs\debug\error\NonExistentClass.java:3: error: Dao class must be annotated with #Dao
public final class NonExistentClass {
^
So far I'm new to Kotlin, but I'm pretty good at Java.
I use Room in this project.
app\build\tmp\kapt3\stubs\debug\error\NonExistentClass.java
package error;
public final class NonExistentClass {
}
error message 2
error: Dao class must be an abstract class or an interface

Null pointer exception: Attempt to invoke virtual method 'c.a.a.a.a.a.c.d0 Database.W()' on a null object reference

My Android app has logged the exception shown below on a smartphone of a user (Huawei P20). com.mypackage.database.Database is a class where I defined the DatabaseEntities and DatabaseDAOs for my Room database (a shortened version is at the bottom). I don't know what W() is.
Does somebody see why this null pointer exception could be thrown? I also have a custom keyboard shipped with my app and in the custom keyboard I'm also writing to the database but that's the first time I got this exception.
java.lang.NullPointerException: Attempt to invoke virtual method
'c.a.a.a.a.a.c.d0
com.mypackage.database.Database.W()' on a null
object reference
--------- Stack trace ---------
c.a.a.a.a.a.d.j.onTouch(Unknown Source:13)
android.view.View.dispatchTouchEvent(View.java:12624)
android.view.View.dispatchPointerEvent(View.java:12873)
android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5771)
android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5535)
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4983)
android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5036)
android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5002)
android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5157)
android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5010)
android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5214)
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4983)
android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5036)
android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5002)
android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5010)
android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4983)
android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7803)
android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7768)
android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7726)
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8007)
android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:202)
android.os.MessageQueue.nativePollOnce(Native Method)
android.os.MessageQueue.next(MessageQueue.java:386)
android.os.Looper.loop(Looper.java:175)
android.app.ActivityThread.main(ActivityThread.java:7625)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
package com.mypackage.database;
import androidx.room.RoomDatabase;
#androidx.room.Database(entities =
{DatabaseEntities.Session.class,
DatabaseEntities.Accelerometer.class,
DatabaseEntities.LinearAcceleration.class,
DatabaseEntities.Gyroscope.class,
DatabaseEntities.MagneticField.class,
DatabaseEntities.Proximity.class,
DatabaseEntities.Light.class,
DatabaseEntities.StepCounter.class,
DatabaseEntities.RotationVector.class,
DatabaseEntities.AudioMode.class,
DatabaseEntities.BackgroundService.class,
DatabaseEntities.KeyboardTouch.class,
DatabaseEntities.KeyboardKey.class,
DatabaseEntities.KeyboardMetadata.class,
DatabaseEntities.KeyboardPrivateMode.class,
DatabaseEntities.KeyboardSession.class
}, version = SettingValues.DB_VERSION, exportSchema = false)
public abstract class Database extends RoomDatabase {
public abstract DatabaseDAOs.AccelerometerDAO accelerometerDAO();
public abstract DatabaseDAOs.LinearAccelerationDAO linearAccelerationDAO();
public abstract DatabaseDAOs.GyroscopeDAO gyroscopeDAO();
public abstract DatabaseDAOs.MagneticFieldDAO magneticFieldDAO();
public abstract DatabaseDAOs.ProximityDAO proximityDAO();
public abstract DatabaseDAOs.LightDAO lightDAO();
public abstract DatabaseDAOs.StepCounterDAO stepCounterDAO();
public abstract DatabaseDAOs.RotationVectorDAO rotationVectorDAO();
public abstract DatabaseDAOs.AudioModeDAO audioModeDAO();
public abstract DatabaseDAOs.BackgroundServiceDAO backgroundServiceDAO();
public abstract DatabaseDAOs.KeyboardTouchDAO keyboardTouchDAO();
public abstract DatabaseDAOs.KeyboardKeyDAO keyboardKeyDAO();
public abstract DatabaseDAOs.KeyboardMetadataDAO keyboardMetadataDAO();
public abstract DatabaseDAOs.KeyboardPrivateModeDAO keyboardPrivateModeDAO();
public abstract DatabaseDAOs.KeyboardSessionDAO keyboardSessionDAO();
}
Edit
My build.gradle file is as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.mypackage"
minSdkVersion 24
targetSdkVersion 29
versionCode 9
versionName "1.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
resValue "string", "app_version", "Version: ${defaultConfig.versionName}"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
resValue "string", "app_version", "Version: ${defaultConfig.versionName}"
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
releaseDebugKey {
initWith release
}
}
signingConfigs {
releaseDebugKey {
// Use the debug signature
initWith debug
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.room:room-runtime:2.2.5'
implementation 'androidx.wear:wear:1.0.0'
annotationProcessor 'androidx.room:room-compiler:2.2.5'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-tasks:17.1.0'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.3.0-alpha01'
implementation 'com.github.AppIntro:AppIntro:5.1.0'
implementation 'com.yuyakaido.android:card-stack-view:1.0.0-beta9'
implementation 'com.github.PhilJay:MPAndroidChart:v2.2.4'
// Glide library
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'androidx.annotation:annotation:1.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation "androidx.preference:preference:1.1.1"
implementation 'org.apache.commons:commons-text:1.8'
implementation 'com.github.warkiz.widget:indicatorseekbar:2.1.2'
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
implementation 'com.llollox:androidtoggleswitch:2.0.1'
}

Can not resolve symbol 'DataBindingUtil' in android?

I want to DataBindingUtil class in java but I cannot import this. It seems to have no DataBindingUtil class even android.databinding.DataBindingUtil in my project. I have tried a reinstall but it not solve my problem. This is my code:
import android.databinding.DataBindingUtil;//cannot import
public class DeviceFragment extends Fragment{
private DeviceViewModel deviceViewModel;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
//cannot use it
DeviceFragmentBinding binding = DataBindingUtil.setContentView(this, R.layout.device_fragment);
And my gradle file (I have enabled viewBinding):
apply plugin: 'com.android.application'
android {
viewBinding {
enabled = true
}
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.aqiapp"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
//custom
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.2'
implementation 'androidx.navigation:navigation-ui:2.2.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//custom
implementation 'com.squareup.retrofit2:retrofit:2.8.2'
implementation 'com.squareup.retrofit2:converter-gson:2.8.2'
implementation 'com.google.dagger:dagger:2.27'
annotationProcessor 'com.google.dagger:dagger-compiler:2.27'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
}
You should enable dataBinding instead of viewBinding try this
android {
...
dataBinding {
enabled = true
}
}
I faced same issue when upgarded to SDK 31, and the reason was databinding is no more under android package but androidx
It worked after
import android.databinding.DataBindingUtil;
was changed to
import androidx.databinding.DataBindingUtil;

Relase build getting crashed but debug is working fine

I am getting error of null in release build only. But when I am creating a release build it is getting crashed but working fine in debug mode.
When I was optimizing my apk i deleted mobile_navigation.xml file but it was never used anywhere
Here is my build file
//one signal integration
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.5'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
//end of one signal integration
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.codon.masterpiece"
minSdkVersion 17
targetSdkVersion 28
versionCode 110
versionName "4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
manifestPlaceholders = [
onesignal_app_id : 'a33a085c-d32d-4462-a850-334f5c73db01',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
release {
minifyEnabled true
//shrinkResources true
//proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res/layouts/home_and_fragments',
'src/main/res/layouts/login_and_onboarding',
'src/main/res/layouts',
'src/main/res'
]
}
}
buildToolsVersion '28.0.3'
compileOptions {
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.exifinterface:exifinterface:1.0.0'
//addedd libraries due to conflict
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
//card view
implementation 'androidx.cardview:cardview:1.0.0'
//Facebook sdk
implementation 'com.facebook.android:facebook-android-sdk:5.2.0'
//Google login
implementation 'com.google.android.gms:play-services-auth:17.0.0'
//Play Store core library
implementation 'com.google.android.play:core:1.6.1'
//Recyclerview
implementation 'androidx.recyclerview:recyclerview:1.0.0'
//Retrofit
// implementation('com.squareup.retrofit2:retrofit:2.6.1') {
// // exclude Retrofit’s OkHttp dependency module and define your own module import
// exclude module: 'okhttp'
// }
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
// exclude Retrofit’s OkHttp dependency module and define your own module import
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
// implementation 'com.squareup.okhttp3:logging-interceptor:4.1.1'
// implementation 'com.squareup.okhttp3:okhttp:4.1.1'
//Volley
implementation 'com.android.volley:volley:1.1.1'
//circle image view
implementation 'de.hdodenhof:circleimageview:2.2.0'
//image crop library
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
//Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
//currency and country picker
//implementation 'com.github.midorikocak:currency-picker-android:1.1.9'
//implementation 'com.github.yesterselga:country-picker-android:1.0'
//country picker
implementation 'com.github.mukeshsolanki:country-picker-android:2.0.1'
//imageview zoom
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
//one signal
implementation 'com.onesignal:OneSignal:3.11.2'
//google analytics
implementation 'com.google.android.gms:play-services-analytics:17.0.0'
//walkthrough
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
//progressbar
//implementation 'com.bigkoo:svprogresshud:1.0.6'
//facebook shimmer effect
implementation 'com.facebook.shimmer:shimmer:0.4.0'
//progress bar
implementation 'com.kaopiz:kprogresshud:1.2.0'
}
Here is my logcat
Process: com.codon.masterpiece, PID: 13865
java.lang.NullPointerException: throw with null exception
at com.codon.masterpiece.d.b.b.a(Unknown Source:3)
at com.codon.masterpiece.ui.home.e$d.a(:341)
at f.g$b$a$a.run(:83)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6746)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Please suggest me what might be wrong in the release mode
Add SerializedName in every field of models which are used in the serialization process by Gson.
import com.google.gson.annotations.SerializedName;
public class Example {
#SerializedName("fieldName")//Add this line for all fields, the name passed in SerializedName should be a key in json
private String fieldName;
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
}
Or
You can keep that model in progaurd rule
-keep class com.codon.masterpiece.model.Example { *; }//use the package name and class name for the models

android cannot find symbol class RequiresApi after removing ACRA

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
}

Categories

Resources