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 have a library which uses all of our apps.
except for shared code and resources i wanted to share gradle code.
each app is constructed:
some_app/
|
- settings.gradle
- build.gradle
|
- mylib/
|
-build.gradle
- other_lib/
- app/
|
- build.gradle
right now i'm talking about the build.gradle in the root dir. The one that defines buildScript closure with dependecies and allprojects{} closure as well.
i tried to use apply from: './mylib/gradle_files/baseProject.gradle'
it works, but then my app can't find the android plugin. for some reason the classpath dependencies were not injected into the build script!
i then tried to create a list and use that:
ext.projectBaseDependencies = ['com.android.tools.build:gradle:2.1.2', 'com.google.gms:google-services:3.0.0']
I then used the list in my closure:
apply from: './mylib/gradle_files/baseProject.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath projectBaseDependencies
}
}
it doesn't work, gradle does not find my variable defined in baseProject.gradle.
I have a hunch that apply from works AFTER buildScript closure is evaluated :-(
Is there any way to share gradle script code across ALL apps ? if not apply from, what CAN work ? skip configuration and config in afterEvaluate {} clause ?
Why not use a Gradle file in your common library? If your common library includes a build.gradle file, you can apply the android library plugin:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
consumerProguardFiles "proguard-rules.pro"
}
}
dependencies {
// Your common dependencies here
}
Then you can include the library in your project's settings.gradle:
include ':mobile'
project(':common').projectDir = new File("/Users/example/path/to/common")
Then add it to your dependencies in the project's build.gradle:
dependencies {
compile project(':common')
// Your other project dependencies
}
This question already has answers here:
Android Test Module (Gradle Plugin 1.3) doesn't work: "debug-classes not found"
(2 answers)
Closed 7 years ago.
We have a project which is using flavors and want to use the new com.android.test plugin available with gradle 1.3 to have our integration tests in a separate project. We've followed the instructions here, but when we try to sync gradle we get the following error:
Error:Configuration with name 'MyFlavorDebug-classes' not found.
Here is our test project's build.gradle file. We have a matching flavor in our app.
buildscript {
repositories {
mavenCentral()
jcenter()
}
}
apply plugin: 'com.android.test'
android {
compileSdkVersion 21
buildToolsVersion = '22.0.1'
targetProjectPath ':MyApp'
targetVariant 'MyFlavorDebug'
}
You should have a structure like this:
root
app
build.gradle
flavor1test
build.gradle
In app/build.gradle
android{
defaultConfig {
applicationId 'com.example.myapp'
}
productFlavors {
flavor1 {
//
}
}
}
In flavor1test/build.gradle something like:
apply plugin: 'com.android.test' // A plugin used for test-only-modules
android {
compileSdkVersion 22
buildToolsVersion = '23.0.0rc3'
defaultConfig {
minSdkVersion XX
targetSdkVersion 22
// The package name of the test app
testApplicationId 'com.example.myapp'
// The Instrumentation test runner used to run tests.
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
// Set the target app project.
targetProjectPath ':app'
targetVariant 'flavor1Debug'
}
dependencies {
// Android Testing Support Library's runner and rules and hamcrest matchers
}
I'd like to add CircularReveal library to my app. I have copied circualreveal folder to .../MyApplication/libs/.
This is my settings.gradle file
include ':app', ':libs:circualreveal'
But when I try to sync project with gradle files there is an error
\AndroidstudioProjects\MyApplication\libs\circualreveal\build.gradle
Error:(2, 0) Plugin with id 'android-maven' not found.
Here is \AndroidstudioProjects\MyApplication\libs\circualreveal\build.gradle file
apply plugin: 'com.android.library'
apply plugin: 'android-maven'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 21
}
}
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
}
What am I doing wrong?
You need to add class path in your project build.gradle. It will look like this:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
I'm trying to work with a project which has two modules, say M1 and M2. M1 should have M2 as a dependency. I've added a class Test to M2 which I want to access from M1.
I'm working with Android Studio 0.3.2. Whatever I try (reimporting project, sync gradle files, ..), I cannot access the Test class from M1: Cannot resolve symbol 'Test'.
Folder structure:
- root
- M1
- src
- build.gradle
- ...
- M2
- src
- build.gradle
- ...
- build.gradle
- settings.gradle
- ...
root/settings.gradle:
include ':M1', ':M2'
root/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
root/M1/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
}
}
dependencies {
compile project(':M2')
}
root/M2/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
}
}
dependencies {
}
Running gradlew compileDebug gives:
root\M1\src\main\java\com\mypackage\m1\MainActivity.java:28: error: package com.mypackage.m2 does not exist
com.mypackage.m2.Test test;
^
What should I do to fix this problem?
Both your module apply the android application plugin with
apply plugin: 'android'
If M1 is to depend on M2, M2 must be a library project, and its gradle file should say
apply plugin: 'android-library'