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
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')
//
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.+'
}
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"
}
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
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 )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.