I am trying to test my ionic app in android studio. It is throwing the below error.
Gradle sync failed: Cause: compileSdkVersion is not specified.
Any solution for this ? What am I doing wrong.
Here is my build.gradle file
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
repositories {
mavenCentral();
jcenter()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1.0'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:+'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:+'
implementation 'com.android.support:appcompat-v7:27.+'
}
You are using android support library of 27.+ so you will have to give sdk version 27 as compileSdkVersion and targetSdkVersion otherwise your project does not know for which platform your project should be built. These parameter should be given in android directory like this in build.gradle(app):
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.abc.test"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Just paste this code below apply plugin: 'com.android.application' this line
In my case , I fixed it by setting the Android gradle plugin version and gradle version to the latest.
If you are working on a old project and using latest version of Android studio then simply change
compileSdk 27
to
compileSdkVersion 27
on your app level build.gradle file. it will fix this error
Please Add Below Line in your gradle file
compileSdkVersion 26
please check below code for reference
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId ""
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Note: There was an error in my app/build.gradle, hence it was not
reading compileSDKVersion property. When I commented such a line, the
error went away:
//def enableHermes = project.ext.react.get("enableHermes", false);
Firstly I got to follow this link:
ReactNative: Building from source
Then this:
ReactNative: android-development-environment
Then you can have this added in your settings.gradle file:
//
include ':ReactAndroid'
//
project(':ReactAndroid').projectDir = new File(
rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
For my ReactViro Sample project I also had to add dependencies from react-native node_modules directory:
implementation project(':arcore_client') // remove this if AR not required
implementation project(':gvr_common')
implementation project(path: ':viro_renderer')
implementation project(path: ':react_viro')
and
in my settings.gradle:
//
include ':react_viro', ':arcore_client', ':gvr_common', ':viro_renderer'
project(':arcore_client').projectDir = new File('../node_modules/react-viro/android/arcore_client')
project(':gvr_common').projectDir = new File('../node_modules/react-viro/android/gvr_common')
project(':viro_renderer').projectDir = new File('../node_modules/react-viro/android/viro_renderer')
project(':react_viro').projectDir = new File('../node_modules/react-viro/android/react_viro')
//
In my case, the error was coming from my own plugin and I fixed it by adding the following line to my plugin.xml file: (which I found simpler than updating the plugin's gradle file)
<platform name="android">
<preference name="android-compileSdkVersion" value="30" />
...
In my case, I resolved the issue by replacing the old plugin applying syntax:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
with the new plugins DSL in all my build.gradle files:
plugins {
id "com.android.application"
id "kotlin-android"
}
Updating required Package.json libraries worked for me try it out. Most of the error will get resolved.
Remove Jcenter() from build.gradle.
Add this below mention code to your android/build.gradle
First, Save your code and uninstall your Android Studio and install again.
Add this line in your android/build.gradle .
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.66, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
You don't need to specify android.buildToolsVersion from Build Tools For buildToolsVersion in version 27.0.3 or higher there's no need to specify buildToolsVersion.
Build Tools 27.0.3 or higher. Keep in mind, you no longer need to
specify a version for the build tools using the
android.buildToolsVersion property—the plugin uses the minimum
required version by default.
Source (developer.android.com)
I want to add to my app some ads using AdMob, the site says I need to add Google Services to the dependencies to use this functionality. So with Android Studio I went to File->Project Structure->app->Dependencies, I clicked on the "+" button e searched for "play-services". What I found was "com.google.android.gms:play-services:9.4.0" so I added it to the dependencies. During the gradle sync however Android Studio sends some errors and stops the gradle sync.
This is the log I get form the sync: http://pastebin.com/ZpN4RUcm
Here some data that might be useful:
Compile SDK Version: API 17
Build Tools Version: 23.0.1
Android
Studio 2.1.2
This is my main gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
And this is my app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:17'
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.serpenssolida.glowdodger"
minSdkVersion 10
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:17.0.0'
compile files('libs/processing-core.jar')
compile project(':facebook')
compile 'com.google.android.gms:play-services:9.4.0'
}
How can I get rid of all the errors?
Change your app gradle file as below and try again:
apply plugin: 'com.android.application'
android {
compileSdkVersion '24'
buildToolsVersion '24.0.2'
...
}
When I am trying to Build an Android Library Project in Android Studio, I am getting the following Gradle error:
Gradle sync failed: Plugin with id 'com.android.library' not found.
I am pretty new to Gradle and this is very confusing for me. Why is this happening?
The build.gradle file is as follows:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
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.0'
}
Your issue is that you are using the top-level file where you can't use this kind of plugin.
In AS you have a structure like this:
Root/
+ lib
| build.gradle
| build.gradle
| settings.gradle
In your top-level file you can use:
// 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:1.3.1'
}
}
allprojects {
repositories {
jcenter()
}
}
In your lib/build.gradle you can use the code posted in the question:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
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.0'
}
Finally in your settings.gradle
include ':lib'
Also you can refer this question.
Assuming you have a standard project structure like the following:
yourProject/
+ .idea/
+ gradle/wrapper/
+ lib-module/
| build.gradle
| build.gradle
| gradlew
| gradlew.bat
| settings.gradle
Your failure to sync seems to indicate an issue with your SDK/IDE config.
Start by opening the "Project Structure" dialog and ensure that the "Android SDK location:" value is set to the correct path.
Second, open the SDK manager and again ensure that you have the correct SDK location path set.
Third, verify that you have the correct version of the "Android SDK Build-Tools" package installed. (23.0.2 in this case)
Finally just to verify that we don't have any bad state I recommend doing an "Invalidate and Restart" from File -> "Invalidate Caches /Restart..."
After all of this I expect that it should sync up. If not try to run ./gradlew from the root of your project and update us with any new information.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0' }
}
apply plugin: 'com.android.library'
Add these lines to gradle file of library.
In my case was due to wrong sdk/ndk paths inside local.properties file, i moved the project from an hd to another and these settings were wrong, fixing the paths fixed the problem.
I'm trying to use MaterialDialog in my project, but this library doesn't support my Right to Left language and I must edit that. After downloading the project and importing it into current project I get this error when building my project:
Error:(2, 0) Plugin with id 'com.novoda.bintray-release' not found.
After many searches on the web I find this link to resolve this. But that doesn't work for my project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
/* I'm adding this below line */
classpath 'com.novoda:bintray-release:0.2.7'
}
}
allprojects {
repositories {
jcenter()
}
}
If you have downloaded the actual library and have imported it to Android studio and modified it then you want to add the dependency in your gradle.build (Module:app). The code you are showing is from gradle.build (Project: NameOfYourProject) so I would delete that line you added there.
Go to the build.gradle (Module:app) file which will look something like shown below and add the library as shown.
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.yourappname"
minSdkVersion 22
targetSdkVersion 22
versionCode 1
versionName "1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':nameOfTheLibrary')
}
Add
dependencies {
compile 'com.afollestad:material-dialogs:0.7.7.0'
}
and press the sync button.
This started happening once I imported jcodec (http://jcodec.org/) for Android into the Studio as a module. The actual project itself compiles fine and works as expected on both devices and emulators but the compiler marks everything involving non-custom libraries as errors. Operations involving custom classes within the project does not have the compiler errors.
I tried the following:
1) Invalidate/Cache restart
2) Deleted the .idea folder and .iml files and reimported the whole project
3) Added the library via Project Structure and Synced Project with Gradle files
The worst part is that this inline compiler error happens for all projects in Android Studio (new and old) now.
I am using Android Studio version 0.5.4.
Is there anything I can do to fix this? Does it have anything to do with jcodec?
jcodec build.gradle files
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 16
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 11
targetSdkVersion 16
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
}
main project build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 11
targetSdkVersion 16
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.android.support:support-v4:19.1.0'
compile files('libs/android-async-http-1.4.4.jar')
compile project(':jcodec')
}