issue with actionbarpull's gradle file - java

I have some build.gradle file this
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
that throws this error :
A problem occurred configuring root project 'NewsFeeder'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not find any version that matches com.github.chrisbanes.actionbarpulltorefresh:library:+.
Required by:
:NewsFeeder:unspecified
But, this reference to chrisbanes's actionbarpulltorefresh seems to be correct : https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-Stock. How can it be since in this project is available in [maven central repo][1] ?
For information, I set in some local.propertiesfile sdk.dir=/home/adt-bundle-mac-x86_64-20130522/sdk, which is the same that what echo $ANDROID_SDK returns

You need to tell gradle where it can look to find the dependency. If you want gradle to use the mavenCentral repository then add this to your build.gradle file:
repositories {
mavenCentral()
}
The buildscript repositories is just for the build script dependencies, not project dependencies. You want to add the repositories entry at the outer most, or project, level.
Your build.gradle would look like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}

Related

How to include android.support in build.gradle using Eclipse

I work with Android 4.4.2 (API 19) and Eclipse. I use the following build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
compile 'com.android.support:support-v7:19.0.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "25.0.2"
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')
}
}
I have the java class
package com.example.ejemplo2;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
I get the error in the Eclipse editor
android.support cannot resolve
How do I have include android.support in build.gradle?. I can't fix this error in Eclipse.
Please use Android Studio... for your own sake.
For what it is worth:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
compile 'com.android.support:support-v7:19.0.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
should be
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOT HERE
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v7:19.0.0' // HERE
}
The reason is you where adding the support lib as a dependency of the build script not a dependency of your java class path

How to override android tests path with Gradle?

For historical reason instrumentation tests are not stored in androidTests directory as required and i can't change directories structure (actually whole app is tests for the library used). I was able to build and install apk with gradle, but no tests were found:
:app-tests:connectedDebugAndroidTest
Tests on test_avd(AVD) - 4.1.2 failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
com.android.builder.testing.ConnectedDevice > No tests found.[test_avd(AVD) - 4.1.2] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack #Test annotations).
:app-tests:connectedDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app-tests:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/asmirnov/Documents/dev/src/project/app-tests/build/reports/androidTests/connected/index.html
Actually the tests are in src folder, written correctly and can be built/runned using Ant:
public abstract class BaseTest extends AndroidTestCase
{
...
public class AppInfoTest extends BaseTest
{
#Test
public void testAllProperties()
{
...
...
How can i make Gradle process src folder as android (instrumentation) tests?
Here is my current build.gradle file (it uses the experimental Android Gradle plugin version 0.7.2 because we have an NDK library):
apply plugin: 'com.android.model.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
model {
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sources {
main {
// overriding paths from default ones to actual ones
// what about 'androidTests' ?
manifest { source {
srcDir '.'
include 'AndroidManifest.xml'
} }
java { source { srcDirs = ['src'] } }
res { source { srcDirs = ['res'] } }
jni {
dependencies {
project ":library" // native library dependency
}
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
}
UPDATE 1 (for sschuberth):
Config:
apply plugin: 'com.android.model.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
model {
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
androidTest {
manifest.srcFile 'AndroidManifest.xml' // error here
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
}
Error
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/asmirnov/Documents/dev/src/project/app-tests/build.gradle' line: 32
* What went wrong:
A problem occurred configuring project ':app-tests'.
> Exception thrown while executing model rule: android { ... } # app-tests/build.gradle line 16, column 5
> Could not find property 'manifest' on source set 'android test'.
Not completely sure this will work for your scenario, but you can update the root of the androidTest sourceSet like this
android {
sourceSets {
androidTest.setRoot('src')
}
}
There is also a test source set if it's just Java code, nothing Android specific.
You could also play around with the java.srcDir setting...
The above setting will look at these locations for your files.
<project>/<module>/src/AndroidManifest.xml
<project>/<module>/src/java
If you'd like to move both into the /src directory, you can use
sourceSets {
androidTest {
setRoot 'src'
java.srcDirs = ['src']
}
}
More Android Gradle details can be read at Configuring the Structure
You are welcome to debug these settings yourself with this setup
sourceSets {
androidTest {
setRoot 'src'
java.srcDirs = ['./src']
}
println "androidTest.manifest.srcFile = ${androidTest.manifest.srcFile}"
println "androidTest.java.srcDirs = ${androidTest.java.srcDirs}"
}
When you just clean the project, you'll see those lines being printed to the console
Instead of sources {} you should use sourceSets {} and the androidTest source set to customize the test source code location:
model { // Required for experimental plugin.
android {
sourceSets {
androidTest {
manifest.srcFile '../AppTest/AndroidManifest.xml'
java.srcDirs = ['../AppTest/src']
res.srcDirs = ['../AppTest/res']
assets.srcDirs = ['../AppTest/assets']
}
}
}
}
Note that this not not apply to unit test. For unit test (like with Robolectric), use the test source set.
It was tricky solution: to use experimental gradle plugin to compile native code with NDK and regular gradle plugin for test app.
build.gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
// experimental gradle plugin for the library to compile native code with NDK
classpath "com.android.tools.build:gradle-experimental:0.7.2"
// regular gradle plugin for the tests
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
subprojects {
task listAllDependencies(type: DependencyReportTask) {}
}
library gradle (experimental):
apply plugin: 'com.android.model.library'
...
model {
android {
...
ndk {
moduleName = "library-jni"
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
stl = "c++_static"
abiFilters.addAll(['armeabi-v7a', 'x86']) // supported abis only
}
...
}
...
}
app/build.gradle (regular):
apply plugin: 'com.android.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion 9
targetSdkVersion 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
}
androidTest {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
jni {
dependencies {
project ":library"
}
}
}
}
}
dependencies {
androidTestCompile project(':library')
androidTestCompile fileTree(include: ['*.jar'], dir: 'libs')
}

NoClassDefFoundError: javax.xml.bind.DatatypeConverter

I am using Amazon's Java SDK in my Android app to communicate with SimpleDB. I added the sdk to the gradle file, and it runs until calls DatatypeConverter.printBase64Binary and I get the following error:
java.lang.NoClassDefFoundError: javax.xml.bind.DatatypeConverter
at com.amazonaws.util.Base64.encodeAsString(Base64.java:36)
at com.amazonaws.auth.AbstractAWSSigner.signAndBase64Encode(AbstractAWSSigner.java:69)
Shouldn't the javax library be included automatically, or at least in the aws build?
Here's my gradle file in case this helps:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.2'
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
// Support Libraries
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:support-annotations:21.0.3'
compile 'com.android.support:support-v4:22.0.0'
compile 'commons-codec:commons-codec:1.5'
compile 'com.amazonaws:aws-java-sdk:1.9.24'
compile 'com.facebook.android:facebook-android-sdk:3.23.1'
compile 'com.github.markushi:android-ui:1.2'
compile 'de.hdodenhof:circleimageview:1.2.2'
compile 'com.afollestad:material-dialogs:0.6.4.5'
compile 'com.android.support:multidex:1.0.0'
compile project(':libraries:MaterialNavigationDrawerModule')
compile('com.crashlytics.sdk.android:crashlytics:2.2.2#aar') {
transitive = true;
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
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')
}
defaultConfig {
targetSdkVersion 21
minSdkVersion 14
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions{
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
unfortunately the package javax.xml.bind.* are not available on android so you cannot use the amazon java sdk.
but for android you could use the aws mobile SDK, please visit http://aws.amazon.com/mobile/sdk/

failing building with gradle

I created a project and I added the following to my build.gradle file, about which I got this error message A problem occurred evaluating root project NewsFeeder. Plugin with id android not found
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Is this your complete build.gradle ?
If so, you are missing
apply plugin: 'android'
usually above repositories block.
Also I think you need buildscript block to identify which gradle to be used.
Example build.gradle looks like
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
maven {
url 'https://github.com/Goddchen/mvn-repo/raw/master/'
}
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v13:13.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
..... other configs .....
}

Android Studio - Gradle: Execution failed for task ':Foo:dexDebug' - but why?

I receive this error :
Gradle: Execution failed for task ':Foo:dexDebug'.
And since 2day ! I have try a lot of solution... But nothing work fine ! Really ! Need Help !
I work with android Studio. (IntelliJ IDEA)
For this following three directory
FooProject [RootProject]
|-gradle
|-libraries
|-facebook [library1]
|-libs
|-android-support-v4.jar
|-res
|-*.(drawable...)
|-src
|-*.java
|-build.gradle
|-AnroidManifest.xml
|-facebook.iml
|-foosdk [library2]
|-res
|-*.(drawable...)
|-src
|-*.java
|-libs
|-YouTubeAndroidPlayerApi.jar
|-build.gradle
|-AnroidManifest.xml
|-foosdk.iml
|-Foo [project for execution]
|-libs
|-commons-io-1.3.2.jar
|-commons-lang3-3.1.jar
|-jackson-core-asl-1.9.11.jar
|-jackson-databind-2.1.4.jar
|-jackson-mapper-asl-1.9.11.jar
|-robospice-1.4.1-SNAPSHOT.jar
|-robospice-cache-1.4.1-SNAPSHOT.jar
|-robospice-spring-android-1.4.1-SNAPSHOT.jar
|-spring-android-core-1.0.1.RELEASE.jar
|-spring-android-rest-template-1.0.1.RELEASE.jar
|-YouTubeAndroidPlayerApi.jar
|-src
|-main
|-java
|-*.java
|-res
|-*.(drawable...)
|-build.gradle
|-AnroidManifest.xml
|-Foo.iml
|-gradlew
|-gradlew.bat
|-local.properties
|-settings.gradle
|-RootProject.iml
I have for my settings.gradle
include ':libraries:facebook', :libraries:foosdk', ':foo'
For the files "build.gradle" :
For libraries/facebook/build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
For libraries/foosdk/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
For Foo/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile project(':libraries:foosdk')
compile project(':libraries:facebook')
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src']
res.srcDirs = ['src/main/res']
}
}
}
Is your Foo project in /Foo or /foo folder (note the upper case)? You may need to correct the include 'foo' to 'Foo'?
If that doesn't work, please paste the info or debug output of your Gradle build. If you're running AndroidStudio and don't have any output, go to the root of your project and run gradlew.bat assembleDebug --info (on Wins) or ./gradlew assembleDebug --info (on Linux/Mac) or --debug and paste the output here so we can see what went wrong exactly.

Categories

Resources