Barcode scanner android build error: compileSdkVersion is not specified

Hey All,

In my project I want to add the native barcode scanner plugin.
After adding the plugin my project android build stops working.

I am running this on macOS Sierra

It throws the following error when running: ionic cordova build android

java.lang.IllegalStateException: compileSdkVersion is not specified.

	at com.google.common.base.Preconditions.checkState(Preconditions.java:456)

	at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:590)
	at com.android.build.gradle.BasePlugin.lambda$null$3(BasePlugin.java:555)
	at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:81)
	at com.android.build.gradle.BasePlugin.lambda$createTasks$4(BasePlugin.java:551)

The result of ionic info

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 8.0.0

local packages:

    @ionic/app-scripts : 3.1.6
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    ios-deploy        : 1.9.2
    Node              : v6.11.4
    npm               : 3.10.10
    OS                : macOS Sierra
    Xcode             : Xcode 9.2 Build version 9C40b

Environment Variables:

    ANDROID_HOME : /Users/username/Library/Android/sdk

Misc:

    backend : pro

My JAVA_HOME is set to
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home

In android studio I installed the following SDK

23 AM

And tools

When removing the plugin, the project builds succesfully.

I tried to set the defaultCompileSdkVersion to 27 in file build.gradle and search throughout the platform folder to set the CompileSdkVersion.

I do not fully understand why this error is thrown.

Can you point me in the right direction to solve this problem.

Your help is greatly appreciated.

1 Like

Exact the same issue for me…
Only removing usage of this plugin can help.
Will set you notify, when will find some solution…

It seems to be a problem with Cordova 7. Downgrading my project to 6.4.0 did the trick for me:

cordova platform rm android
cordova platform add android@6.4.0

Hope the plugin will be fixed to be runnable at cordova 7.

4 Likes

I downgraded my project as well. This also did the trick for me. Thank you

This fixed the issue, thanks!

This allowed me to build on android:

ionic cordova platform rm android
ionic cordova platform add android@6.3.0

i have tried but
not worked for me