I recently updated Android Studio to version 0.3.0 and now there are no build variants I can choose from. I have tried cleaning and rebuilding the project, and restarting Android Studio with no success. My build.gradle is
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
versionCode 10
}
productFlavors {
lite {
packageName "com.lvl.xpbar"
versionCode 11
}
pro {
packageName "com.afewguys.raisethebar"
versionCode 1
}
}
sourceSets {
main {
manifest.srcFile '/src/main/AndroidManifest.xml'
java.srcDirs = ['/src/main/java','.apt_generated']
resources.srcDirs = ['/src/main/java','.apt_generated']
aidl.srcDirs = ['/src/main/java','.apt_generated']
renderscript.srcDirs = ['/src/main/java','.apt_generated']
res.srcDirs = ['/src/main/res']
assets.srcDirs = ['assets']
}
lite {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
pro {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
Any help is greatly appreciated
You need to sync project with Gradle files:
In current versions of Android Studio: File -> Sync Project with Gradle Files.
In old versions (pre 3.0): Tools -> Android -> Sync Project with Gradle Files
In your /gradle/gradle-wrapper.properties file update the following setting to:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-all.zip
Now, go to Tools -> Android -> Sync Project with Gradle Files
This will download the latest distribution of Gradle and automatically reload your project and build variants after it's finished.
Make sure to update your project's build.gradle files to
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
Related
I wanted to open up and project in Android studio that I haven't worked on in a while, but when Android Studio tries to load the project it fails with this error message:
Error:(21, 0) Cannot set the value of read-only property 'jniFolders' on task ':android:packageDebug'.
I click on the link to the build.gradle and I guess these lines are the problem ...
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
I see an answer here: Google AppInvites break build that says to ...
Fixed by adding this instead:
android {
sourcesets {
main {
jniLibs.srcDir new File(buildDir, 'lib')
{
}
}
But the above answer is not very clear. I am not sure what line to change and the braces in the answer do not seem to match up.
I am at a total loss at what to do? Any help is appreciated.
Thanks
Ok I had to change the start of my build.gradle file to this ....
android {
buildToolsVersion project.androidToolsVersion
compileSdkVersion project.androidSDKVersion.toInteger()
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDir 'libs'
}
instrumentTest.setRoot('tests')
}
}
/*RBC
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
RBC*/
I added the line:
jniLibs.srcDir 'libs'
and I commented out
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
In the C:\Users\plankton\Desktop\ThePlaneThatCouldntFly\flappytrip\android\build.gradle file.
I came about this solution after reading this https://github.com/libgdx/libgdx/issues/3027
I faced this same problem when trying to import the libgdx-cookbook samples from "Libgdx Cross-platform Game Development Cookbook" into Android Studio 2.1.1. In my case, it was solved by simply:
importing the /samples project;
not upgrading the Gradle plugin when prompted;
updating build.gradle file under the android subproject to make it use the buildToolsVersion and compileSkdVersion that I had:
buildToolsVersion "23.0.3"
compileSdkVersion 23
trying again.
So it maybe has to do with the version of the Gradle plugin.
Hello I am new to android studio. I have a existing eclipse project, which runs on (2.3.3 android api 10) only.
When I migrate my existing eclipse project to android studio. I face below error.
Error:Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
Possible causes for this unexpected error include:
You are using JDK version 'java version "1.7.0_75"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
Please update to a newer version (e.g. 1.7.0_67).
Open JDK Settings
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Here is my build.gradle file.
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
}
android {
compileSdkVersion 10
buildToolsVersion "10"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 10
}
}
Can anyone help me. Thanks in advance.
I solved the problem.
I just have to change my buildToolsVersion.
From
buildToolsVersion "10"
to
buildToolsVersion "19.1.0"
Now its works perfectly.
Thanks,
please ensure your sdk is newer than jdk1.7.0_67.
open your android studio preferences page for check.
I'm just migrated from Eclipse. My project keeps the old structure like below
projRoot\
src\
res\
...
AndroidManifest.xml
tests
build.gradle
Here's content of build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest.setRoot('tests/src')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
testApplicationId 'com.xxx.yyy.test'
testInstrumentationRunner 'android.test.InstrumentationTestRunner'
testHandleProfiling true
testFunctionalTest true
}
}
I'm on Android Studio 0.8 beta, Gradle 1.12, I tried every possible solution found all over SO and google without any success.
Anyone can help out? Thanks.
In addition, where can I know the current version of Android Gradle plugin?
For test source set structure, follow this link. It is mentioned that test source sets should be setup as follows:
for local unit tests: module-name/src/test/java/
for android instrumentation tests: module-name/src/androidTest/java/
In case it's still doesn't work. Android Studio may encounter sometimes issues with the recognition of the tests. And the workaround would be to run local tests by using the command line:
./gradlew testVariantNameUnitTest
Once the command is run. You can go back to Android Studio and run the tests and it should work. You can find more on running tests using command line on this link.
Hope this helps.
I decided to download android studio because of pretty good look and popularity. First problem i met is adding external library. Most tutorials are for older versions. Things i did:
Created 'libraries' directory and put THIS library inside
Inside settings.gradle added
include ':app:libraries:drawer'
Inside src in build.gradle added
compile project(':app:libraries:drawer')
under
dependencies
After pressing "sync project wih gradle files" i got:
Gradle 'SCR' project refresh failed:
Cause: cannot get property 'compileSdkVersion' on extra properties extension as it does not exist
Pastebin sourcefiles:
settings.gradle inside project: http://pastebin.com/NvuPG1St
build.gradle inside project: http://pastebin.com/AT0Kjj8F
build.gradle inside src: http://pastebin.com/HjTKUazU
What should i do?
Use this structure:
root
app
build.gradle
libraries
drawer
build.gradle
build.gradle
settings.gradle
Change your settings.gradle with
include ':app'
include ':libraries:drawer'
Change dependency in your app/build.gradle
compile project(':libraries:drawer')
In build.gradle inside the drawer you have to specify your sourceset inside the android block.
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['aidl']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
UPDATE (after your images):
In your drawer/build.gradle you are using:
compileSdkVersion parent.ext.compileSdkVersion
buildToolsVersion parent.ext.buildToolsVersion
You should define in your root/build.gradle
ext {
compileSdkVersion = 19
buildToolsVersion = "19.0.3"
}
and change the drawer/build.gradle in:
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
Controlling Android properties of all your modules from the main project
// SDK Version and Build Tools used by all subprojects
ext {
compileSdkVersion = 21
buildToolsVersion = '21.1.2'
}
I've looked all over stackoverflow, google, xda, etc. But Can not seem to find out how to add an sdk to my android studio project. I'm trying to use the 500px-android-sdk, but every time I try to import it in my main activity file, android studio doesn't recognize it. I'm getting errors like it can't be found.
MainActivity.java:
import com.fivehundredpx.api
Which is currently not importing correctly
In settings.gradle
include ':myapp'
include '500px-android-sdk'
project('500px-android-sdk').projectDir = new File('libs/500px-android-sdk')
and my build.gradle is empty as I just cleaned it.
It appears that this SDK was created before Android Studio came out. Perhaps adding a gradle build file that sits in the same directory as the SDK's AndroidManifest.xml will solve the problem?
Here is my best guess as to what the build.gradle would look like.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+',
compile files (
'signpost-commonshttp4-1.2.1.1.jar',
'signpost-core-1.2.1.2.jar'
)
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}