Add menudrawer (external library) to Android Studio 0.5.2 - android

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'
}

Related

Add Ant Library Project into my Gradle project

I have a Gradle Android project, which includes an Ant library project: https://github.com/pakerfeldt/android-viewflow.
How can I include this Ant library project in my build.gradle file? I tried to added "ant.importBuild 'lib/viewflow/build.xml'" but didn't work.
Is there anything missing or mistake here?
Thanks
This is a similar question to android-studio-library-not-recognizing-the-android-api.
In the viewflow directory you'll need to create a build.gradle file with the following content:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: 'android-library'
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
compileSdkVersion 19
buildToolsVersion "19.0.3"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
}
You have the option of including the generated AAR file into your project's libs folder like the linked question or you can copy the viewflow project into your projects root directory and include it as a module by modifying your settings.gradle and adding it your project's dependency section using compile project:
compile project(':viewflow')

Can't compile Android project with gradle after adding a library

Before adding a library to my Android project the layout was like this:
MyappProject
Myapp
build.gradle
settings.gradle
build.gradle
The top level build.gradle has always been empty, with the settings.gradle file containing only:
include ':Myapp'
I obtained a library project which I was able to import successfully into Android Studio, so I presume that the gradle files within it were fine. I now have the following structure:
MyappProject
Myapp
build.gradle
libraries
Library
LibrarySubProject1
build.gradle
....
build.gradle
settings.gradle
build.gradle
...and the top level settings gradle now looks like:
include ':Myapp'
include ':libraries:Library'
I've also updated Myapp's build.gradle so it includes the extra last line in dependencies here:
dependencies {
compile 'com.android.support:support-v4:+'
compile files('libs/commons-lang3-3.1.jar')
compile files('libs/jsoup-1.7.3.jar')
compile project(':libraries:Library')
}
Unfortunately, any attempt to do anything with gradle (sync files, build etc.) now gets me the following:
Gradle 'MyappProject' project refresh failed:
Configuration with name 'default' not found.
Gradle settings
Any changes to the settings appear to have no effect, and Android Studio keeps the settings set to "use default gradle wrapper".
From what I understand, that means that there is a problem with the top level build.gradle along the lines of this file not containing sufficient information to build the sub projects. But, perhaps I have misunderstood, as Myapp used to build and Library also seems fine. Removing the compile project(':libraries:Library') allows gradle file syncing again, but I would like to use that library...
Any suggestions as to how to fix this would be welcome.
Edited to add build.gradle from Library. Top level:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
version = VERSION_NAME
group = GROUP
repositories {
mavenCentral()
}
}
From the next level:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
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')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
You cannot have project inside a project in Android Studio. You can only have modules so change your project structure as shown below so that it will be compliant for the allowed project - module level structure.
MyappProject
Myapp
build.gradle
libraries
LibrarySubProject1
build.gradle
....
settings.gradle
build.gradle(Root only one)
Now do the following with your build.gradle files
1. Root level build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
If you have something in your library project's root level build.gradle file include that also in this root level build.gradle file because only root is allowed to have which will automatically be included in each of the sub level's build.gradle files while compilation .
2. LibraryProject's build.gradle file
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
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')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
3. Your main module's build.gradle file should look like
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
}
dependencies {
//YOUR MODULE DEPENDENCIES
compile project(':libraries:LibrarySubProject1')
}
your settings.gradle file will be like
include ':Myapp'
include ':libraries:LibrarySubProject1'
In my case the problem was solved simply by deleting the line containing
maven_push.gradle
this line was trying to upload the project to maven while I didn't need to.
Your library has a multimodule build file structure:
Library
LibrarySubProject1
build.gradle
....
build.gradle
with the two-level build.gradle file structure like Android Studio-made projects have, but that doesn't work for libraries. MyApp is pulling in the dependency for :libraries:Library but only sees that top-level build file with the buildscript and allprojects tags, and it can't find a default configuration in there to depend on.
Your library can't have a settings.gradle file to lead the way to LibrarySubProject1/build.gradle. What you'll need to move the library one directory level up to Library, and collapse the two build.gradle files down to one:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
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')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
I'm not sure what to do about the VERSION and GROUP stuff you're doing in the top-level build.gradle; you'll have to figure that out.
I just commented out line:
apply from: rootProject.file('gradle/maven-push.gradle') in
build.gradle(:library) since I don't want to publish this project at all, but I need it just as a library.

Android Studio - Build variants not showing up

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.+'
}

import sdk to android studio

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']
}
}
}

HoloEverywhere, ActionBarSherlock with Gradle gives 'Attribute xxx has already been defined'

I'm trying to migrate from Maven to Gradle with my project.
So far we used HoloEverywhere v1.6.1 and ABS v4.3.1 and with Maven everything worked fine.
Now I'm upgrading to HoloEverywhere v2.0.0-SNAPSHOT (latest master # https://github.com/Prototik/HoloEverywhere) and ABS v4.4.0
HoloEverywhere build.gradle is kept intact.
This is my project library build.gradle configuration:
apply plugin: 'android-library'
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile project(':contrib:holo-everywhere:library')
compile project(':contrib:holo-everywhere:addons:slider')
compile project(':contrib:holo-everywhere:addons:preferences')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
What am I missing here? Should I remove ABS here altogether because of new support-v4:18.0.1 library?
Yeah. Don't use ABS + HoloEverywhere v2.0.0+ together.
I accidentally checked the checkbox in Android Studio which adds the ActionBarCompact to the new project. Trying to add ABS gave me the same error. removing compile 'com.android.support:appcompat-v7:18.0.0' solves this issue.

Categories

Resources