Android Studio update today with regression - gradle

Started Android Studio today, and it popped up an update notice. Since I'm eager to explore new features and bug fixes, I clicked yes. Now the Project Structure dialog where you setup dependencies is missing, and has been replaced by a message:
We will provide a UI to configure project settings later. Until then, please manually edit your build.gradle file(s.)
So, I go out to try to figure out how to add ActionBarSherlock to my project as a project dependency, and have hit a brick wall. I have no idea how to import ActionBarSherlock project as a Library Project, and configure my project to use it. There isn't much documentation on this at Google, IntelliJ, and the Gradle docs assume a LOT of pre-existing knowledge of build systems.

There are plenty of posts on SO how to do this (although referenced with already missing Project structure dialog)
How do I add a library project to Android Studio?
Android-Studio ActionBar sherlock error with gradle
Installing ActionbarSherlock with Android Studio?
Problems importing project into Android Studio regarding ActionBarSherlock
In short:
Create a folder (i.e. /libraries) in your root.
Extract actionbarsherlock there
Create a new file build.gradle in actionbarsherlock root with the following contents
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
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']
}
}
}
In your project's build.gradle
dependencies {
//NOTE that "libraries" is actually a folder name you created in step 1
compile project(":libraries:actionbarsherlock")
//Any other dependencies here
//Make sure there is no android-support-v4.jar in this build file
//as it is already contained in actionbarsherlock project
}
In settings.gradle
//NOTE that "libraries" is actually a folder name you created in step 1
include ':libraries:actionbarsherlock', ':<Your project name>'
EDIT
Last step: Close your project and open it back again for Studio to pick up the Intelli-sense data

Related

Gradle - Make existing android project a child of other project and run "gradlew tasks"

Part 1.
I have an existing Android project which is built with gradle.
settings.gradle looks like this:
include ':android', ':androidTest', ':androidTestApp'
build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}
task customClean(dependsOn: [':android:clean', ':androidTest:clean', ':androidTestApp:clean']) {
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
}
}
What I need to do is a create a project that is a parent of this android project and runs this android project tasks. I add to settings.gradle of new root project only include 'android-sdk:android'which is all I need for now. And everything works fine, I can run tasks of android project like this gradlew androidBuild:
task androidBuild(dependsOn: 'android-sdk:android:assemble') << {
group unitySdkGroupName
}
Problems arise when I run gradlew tasks on the new root projects. I get
Caused by: org.gradle.api.UnknownTaskException: Task with path ':android:clean' not found in project ':android-sdk'.
I know I can fix this by removing colons like this, but I want to somehow make tasks command work without changing android project if possible.
task customClean(dependsOn: ['android:clean', 'androidTest:clean', 'androidTestApp:clean']) {
}
Part 2.
When I add to settings.gradle of root project other nested projects
include 'android-sdk:androidTest'
include 'android-sdk:androidTestApp'
I get errors here in dependencies sections of child projects that are dependent on android module (this is androidTest module):
dependencies {
compile project(path: ":android")
compile 'com.google.android.gms:play-services:7.3.0'
}
and getting this when I refresh projects (again seems like relative paths issue):
Error:(30, 0) Project with path ':android' could not be found in project ':android-sdk:androidTest'.
So the question is - can I make gradlew tasks command work properly without modifying the underlying android project and how can it be done the most elegant way?
Unfortunately: no. Nested multiproject builds are not possible. I should add yet, but although intention to support them has been shown, there is absolutely no indication of when this feature can be expected.
See https://discuss.gradle.org/t/nested-multimodule-builds-with-a-flat-directory-layout/7509/13
I could not even find a feature request at https://discuss.gradle.org/c/bugs

Can't install Kontakt Android SDK using Gradle on Android Studio

I'm trying to install the Android SDK from Kontakt into a project in Android studio. I'm following the (seemingly basic) instructions on the Kontakt site here:
http://docs.kontakt.io/android-sdk/quickstart/#installing-the-sdk---android-studio
In brief, these steps say add maven { url 'http://repo.kontakt.io/repository/internal/' } in the repositories in your top-level build file, and add to add compile 'com.kontakt.sdk.android:library:1.0.5' in the dependencies in the main module build file.
However, when I try to sync my project with the updated files, it fails with an error message:
Error:Failed to find: com.kontakt.sdk.android:library:1.0.5
I tried with a totally fresh project and the same issue.
I'm guess this all has something to do with the fact that the instructions are written for Android's 0.12 version of the Gradle tools, but I'm using v1.1.0. I'm not across the detail of Gradle, so so any help would be appreciated.
My guess is that path to Kontakt.io public repository should be added to allprojects section instead of buildscript.
allprojects {
repositories {
jcenter()
maven { url 'http://repo.kontakt.io/repository/internal/' }
}
}
I am not 100% sure so don't shoot me:P
I think adding this line:
-->compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.kontakt.sdk.android:library:1.0.6'
Directly above the gradle project I wanted to compile fixed it.
Go to the Kontakt.io Android Proximity SDK https://github.com/kontaktio/kontakt-android-sdk on GitHub.
Click the Download ZIP button
Un-zip the file to a temporary location.
Add the jar file in your Android Studio Project.
File -> New Module -> Import .JAR/ .AAR Package -> Click Next -> Browse the SDK path (2.1.1) -> Finish (Take time to add in the project)
Then, Add module in dependencies
Right Click on Project Name -> Open Module Settings -> Under the list (Modules) -> Click on Dependencies -> Click on '+' -> Module Dependency -> Add Kontakt.io-android-sdk
Now Build your project It worked for me to kontakt io SDK. If anybody find the way to do this as Gradle build, please let me know.

Gradle error on Android Studio startup

Every time I start Android Studio I get the following error:
Gradle 'VertretungsplanProject' project refresh failed: Could not
fetch model of type 'IdeaProject' using Gradle distribution
'http://services.gradle.org/distributions/gradle-1.6-bin.zip'. A
problem occurred configuring project ':Vertretungsplan'. A problem
occurred configuring project ':Vertretungsplan'. Failed to notify
project evaluation listener. A problem occurred configuring project
':libraries:actionbarsherlock'. Failed to notify project evaluation
listener. Could not normalize path for file
'P:\Projekte\VertretungsplanProject\libraries\actionbarsherlock:Vertretungsplan\libs\android-support-v4.jar'.
The syntax for the filename, directoryname or the volume label is
wrong
My project looks like this:
Gradle settings:
build.gradle of :Vertretungsplan:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/commons-io-2.4.jar')
compile project(':libraries:actionbarsherlock')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
build.gradle of :VertretungsplanProject is empty.
build.gradle of :actionbarsherlock:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile files(':Vertretungsplan/libs/android-support-v4.jar')
}
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']
}
}
}
When I want to compile now this error appears:
Deprecated make implementation
Old implementation of "Make" feature is enabled for this project.
It has been deprecated and will be removed soon.
Please enable newer 'external build' feature in Settings | Compiler.
After changing this setting to Use external build everything is working fine.
But this appears every time I start Android Studio and this is really annoying.
UPDATE
I deleted the android-support-v4.jar from the libs folder and simply wrote compile 'com.android.support:support-v4:18.0.0' to the build.gradle of ActionbarSherlock. Then the android-support-v4.jar is used from the installed SDK.
EDIT
Go to File > Settings > "Build,Execution,Deployment"> Compiler
Click compiler directly.
Check the option: Use external build > Apply > OK.
It worked for me !! :)
You seem to have more than one issue. Problems loading gradle on startup and problems resolving the dependency path name in your environment.
I recently found a fix for the "Failed to import Gradle project" issue, which could be linked to your dependency issue.
At least if you fix one, you know your issue could specifically be the dependency path resolution rather than a gradle/android studio issue...
Check out the troubleshooting section here:
http://developer.android.com/sdk/installing/studio.html#Troubleshooting
The basic steps are:
1. Close android studio
2. Open the SDK manager
(run android binary/executable which should be in /tools)
3. Scroll down the list and expand extras
4. Tick the "Android Support Repository"
5. Click Install Packages.. etc etc...
You need to download this as Android Studio 0.2.x needs a new maven repository used by the new build system for the support library, instead of using support library jar's.
Let us know if anything changes after trying this fix.
In the error message, the path appears: 'P:\Projekte\VertretungsplanProject\libraries\actionbarsherlock\:Vertretungsplan\libs\android-support-v4.jar'
It looks like you're on Windows. The semicolon before Vertretungsplan is not a legal filesystem character. This appears in your script as
compile files(':Vertretungsplan/libs/android-support-v4.jar')
Try changing this to
compile files('Vertretungsplan/libs/android-support-v4.jar')

Gradle/Android: Specify 'root' as a dependency of subproject

First of all, I've got an Android Studio project setup that works fine from within Studio. I can build it and run it on a device and in the emulator without problem and can also build a release APK.
I'm now trying to get to the point where I can have some command-line tools that will handle my build for me. All the reading I've done suggests that Android Studio uses gradle, but from what I've seen that's clearly not the case for my project -- as I had to create my build.gradle, settings.gradle files before gradlew would even attempt to build anything -- and yet Android Studio could still compile and deploy just fine.
Here's my project structure (as it sits physically on disk):
Root Project (Android library project, contains all the src, logic, UI, activities, etc.)
\--- WrapperProject (Android app, depends on the root project)
\--- SubProject1 (Android library, used by root)
\--- SubProject2 (Android library, used by root)
This is my root project's settings.gradle file
include ':SubProject1', ':SubProject2'
Likewise, here's my root project's build.gradle file. Note that this project is marked as an android-library and does not reference the WrapperProject in any way (should it?)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile project(':SubProject1')
compile project(':SubProject2')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I'm able to build my root project successfully using gradlew build -- but my ultimate goal is to build the APK from the WrapperProject that has a dependency on the root project. Can you suggest what my WrapperProject's build.gradle file should contain?
I'm here because of searching for similar answers, although my problem is primarily the opposite. I'm finding that the integration between command-line builds (gradlew) and Android Studio 0.2.2 is full of secrets.
One thing I see that stands out in your config file: this is pretty beta/alpha stuff. You have not revised your project to the latest Android Studio 0.2.0 notes. In particular, the 'com.android.tools.build:gradle:0.4' should be revised. Reference: http://tools.android.com/recent
There is an open source application that has the same basic need as yours. It is a Grocery Shopping app that is provided as a sample for CouchDBLIte https://github.com/couchbaselabs/GrocerySync-Android
it has to reference the existing projects. It seems to use a more explicit syntax for the dependencies than you did. example: "compile 'com.couchbase.cblite:CBLiteEktorp:0.7.4'" - including the full class paths. But they define two basic approaches, direct integration and artifact integration.
Sorry I can't provide a more precise answer to your syntax issue - but I'm sharing what I know so far.

Can't add custom Library Project with Android Studio

I've created an Android Project with Android Studio, and usually everything just works fine.
However, whenever I try to add a new custom Android Library Module or just a project with an Android Library Module I get the following error:
Failed to import Gradle project: Could not fetch model of type 'IdeaProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
A problem occurred configuring project ':MyLibrary'.
A problem occurred configuring project ':MyLibrary'.
Failed to notify project evaluation listener.
Main Manifest missing from C:\Users\cku\AndroidStudioProjects\MyApplicationProject\MyLibrary\src\main\AndroidManifest.xml
Consult IDE log for more details (Help | Show Log): Failed to import Gradle project: Could not fetch model of type 'IdeaProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
A problem occurred configuring project ':MyLibrary'.
A problem occurred configuring project ':MyLibrary'.
Failed to notify project evaluation listener.
Main Manifest missing from C:\Users\cku\AndroidStudioProjects\MyApplicationProject\MyLibrary\src\main\AndroidManifest.xml
Consult IDE log for more details (Help | Show Log)
I've followed this answer and this answer with no luck.
Any help is appreciated, thx!
I believe the build.gradle file of the project you are trying to import do not specify the right paths because it can't find AndroidManifest.xml:
Main Manifest missing from C:\Users\cku\AndroidStudioProjects\MyApplicationProject\MyLibrary\src\main\AndroidManifest.xml
It is trying to locate AndroidManifest.xml inside the default folder structure which should be:
-Project
- src
-instrumentText
-main
-java
-res
AndroidManifest.xml
As you are importing a project I believe it has other folder structure, which you should inform in build.gradle like this:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
And make the necessary changes to reflect the folder structure of the project you want to import.
Just recently (Android Studio 0.2.6) I've tried this again in another project, with no success at all. A co-worker has experienced a similar issue. Now the wizard for creating new modules simply appears blank. It seems to be a genuine bug of Android Studio (which in all fairness is still in early development).
The way to go is to create a new project with only a library in it and then copy its single module over to the existing project. Tinker with the gradle scripts until it builds on the command line. Then go ahead, close Android Studio and delete the .idea directory of your project and all .iml files (there should be one at the root of the project and one at the root of each module). Finally, re-open Android Studio and re-import the project using the gradle.build file in the project root.
Edit: Seems to have gotten more reliable with Android Studio 0.2.8

Resources