I am new to Android and decided to create a new project with the default Login Activity template. Without making any change, just outside the box, I get many lintern errors in different java classes. The errors are at the import
statements and they refer to multiple classes inside the navigation package.
NOTE #1
While similar, this question is NOT a duplicate from this, because in that case they are usingandroid.arch
instead ofandroidx.navigation
, besides they solved it by adding the dependencies (That is not my case, keep reading) And this question is also NOT a duplication from this, because that question references a different class (ViewModelProviders, with an s).
NOTE #2
The application works indeed. When running emulator, it compiles and runs normally.
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
NOTE #3
Classes from other packages insideandroidx
are imported successfully.
So, surely this has something to do with the implementations in the gradle script. Here it is:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 32
buildToolsVersion "32.0.0"
defaultConfig {
applicationId "com.memyselfandi.logindroid"
minSdkVersion 25
targetSdkVersion 32
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.annotation:annotation:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
You can see the androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1
.
I also tried adding androidx.lifecycle:lifecycle-extensions:2.2.0
and syncing, but it didn't worked.
In any case, since the app is able to compile and run as state in note #2, it should be an android studio issue, but i have no idea what could be wrong there. I already cleaned the project, the cache, restarted the IDE and the PC.
After a little research and by running a gradle task named lintFix
I get the following error:
Caused by: java.lang.ClassNotFoundException: com.android.tools.lint.client.api.Vendor
Edit: More information
I tried adding classpath "com.android.tools.lint:lint:30.2.2"
to the project's gradle script. It throws a different error when :
java.lang.NoClassDefFoundError: com/android/tools/lint/model/LintModelModuleLoaderProvider
> com/android/tools/lint/model/LintModelModuleLoaderProvider