Reputation: 43
I have seen many examples in different android libraries about detecting if device is LOLLIPOP supported or not. But when I use it in my app, it is throwing the following error:
Error:(20, 60) error: cannot find symbol variable LOLLIPOP
For example my source code is:
static boolean isLollipop() {
return Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1;
}
I am using the latest version of Android Studio with all packages updated and installed.
Error is on this statement:
Build.VERSION_CODES.LOLLIPOP
Also when I check options of VERSION_CODES
, LOLLIPOP
does not exist in that list.
Upvotes: 3
Views: 8978
Reputation: 384
If androidx and androidx-adapter plugins are already added then you have to remove these plugins. The trick is to add the platform before adding these plugins back in your project.
You will have to remove the platform if it is already added.
ionic cordova platform rm android
ionic cordova plugin rm cordova-plugin-androidx
ionic cordova plugin rm cordova-plugin-androidx-adapter
After removing these things from your project, you can add the platform (android in this case) and then you will have to add the plugins to resolve this issue.
ionic cordova platform add android
ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter
After following these steps, simply build the project and the errors will be gone!
Upvotes: 0
Reputation: 747
> Task :app:compileDebugJavaWithJavac FAILED
<Ionic-app>\platforms\android\app\src\main\java\com\ionicframework\cordova\webview\IonicWebViewEngine.java:11: error: package android.support.annotation does not exist
import android.support.annotation.RequiresApi;
^
<Ionic-app>\platforms\android\app\src\main\java\com\ionicframework\cordova\webview\IonicWebViewEngine.java:137: error: cannot find symbol
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
^
symbol: class RequiresApi
location: class IonicWebViewEngine.ServerClient
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
For last few days, I was struggling with above error with latest cordova-android version 9.0.0
ionic cordova plugin add cordova-plugin-androidx-adapter
Finally, the issue got resolved by installing above plug-in.
Upvotes: 5
Reputation: 152
Add to build.gradle of module.
api 'com.android.support:support-annotations:27.0.0'
Upvotes: 0
Reputation: 172
I pasted Your code it works for my. try comparing Your code with my gradle.build. and let me know if you got rid of that problem or not
apply plugin: 'com.android.application'
android {
compileSdkVersion 26 //THIS GUY
buildToolsVersion "26.0.2" //THIS GUY
defaultConfig {
applicationId "com.example.piotr.myapplication"
minSdkVersion 15
targetSdkVersion 23 //THIS GUY
versionCode 1
versionName "1.0"
}
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:26.0.2' //THIS GUY
compile 'com.android.support:design:26.0.2'
}
Upvotes: 0
Reputation: 19351
it seems to that you're using old build tools or you're missing some libraries.
I pasted your code into my Android Studio and it works.
Please compare your build.gradle
with this one:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23 //THIS GUY
buildToolsVersion "23.0.2" //THIS GUY
defaultConfig {
applicationId "com.example.piotr.myapplication"
minSdkVersion 15
targetSdkVersion 23 //THIS GUY
versionCode 1
versionName "1.0"
}
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:23.1.1' //THIS GUY
compile 'com.android.support:design:23.1.1'
}
I've already matched parts which might be important to your code.
Hope it help
Upvotes: 2