I am using gradle in Android studio for an android project. I have a jar that I downloaded called TestFlightAppLib.jar. This jar isn't present in the maven repository so I can't just put it in my build.gradle.
How can I add this JAR file to my project? I don't see any option to add an external jar to the project.
Update
This is my complete build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.retrofit:retrofit:1.2.2'
compile 'com.github.rtyley:roboguice-sherlock:1.5'
compile 'org.roboguice:roboguice:2.0'
compile files('libs/TestFlightLib.jar')
}
This is the error message:
Gradle: Execution failed for task ':MyProject:compileDebug'.
> Compilation failed; see the compiler error output for details.
/Users/droid/android/MyProjectProject/MyProject/src/main/java/com/mypkg/ui/activity/MainApplication.java
Gradle: error: package com.testflightapp.lib does not exist
Here is the class:
import com.testflightapp.lib.TestFlight;
public class MainApplication {
}
just add
compile fileTree(dir: 'libs', include: '*.jar')
to your dependencies in the build.gradle then all the jars in the libs folder will be included.
Put the jar in a folder called libs (created on the root of your project). Once moved right click on the jar and you will find "add as library". Click on it and select the module!
Related
I have a project that need to use protobuf (Getting the objects from server and parsing them).
For that I configured the following things:
Project level gradle.build
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
classpath 'com.google.protobuf:protobuf-java:2.6.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level gradle.build
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.protobuf'
android {
...
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:2.6.1'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.protobuf:protobuf-java:2.6.1'
compile 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
}
I put my proto file under .../app/src/main/proto/FILE.proto.
Once i am trying to build the project I am getting the following error:
Error:Execution failed for task ':app:generateDebugProto'.
> protoc: stdout: . stderr: /Users/XX/YY/app/build/extracted-protos/main: warning: directory does not exist.
/Users/XX/YY/app/build/extracted-include-protos/main: warning: directory does not exist.
...
protoc-gen-javanano: program not found or is not executable
--javanano_out: protoc-gen-javanano: Plugin failed with status code 1.
Any idea why is that? It should use the protoc from the repo and is should support that nano compilation.
Thanks.
Finally i downloaded the source from GitHub and compiled it. It fixed the issue because it includes the missing binary.
Hello I am working on a project for which I am using Android Studio. I have setup everything but when I run my project then I get below errors. I could not resolve it for last 2 days. What could be the problem in my project that causing this error
Please help if anyone know about this.
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "in.xyz"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.+'
//compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
//compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
...
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ': app:dexDebug'.
settings.gradle
include ':app'
include ':multiStateToggleButton'
Your problem i believe is that wherever you are linking the Library to your Main Project you have the same dependencies between the two for your support library and annotations.
If you have the library project as a dependency in your application you will only need the dependency to be placed in the library dependencies closure.
The issue is that you have two dex files because there are two Files with the same name because the overlap in files with your dependencies.
First copy your module to your libs/ folder of your main project then,
create your settings.gradle file in the root of the main project:
include 'app_name', 'library_name'
project(':LibraryNameGoesHere').projectDir = new File('libs/LibraryNameGoesHere')
For your library's build.gradle
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:support-annotations:20.0.0'
}
Then for your main project build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.+'
compile project(":libs:LibraryNameGoesHere")
}
Since facebook sdk configed for using Android 2.3.3, it requires annotaion lib.
My app configed for using Anndoid > 4.x.x, which is contains Annotation, the conflict was emarged.
I have changed, in the facebbok mainfest, to work with Android > 4.x.x and it solved the problem.
if you migrate the project from eclipse to studio , and then your project need a new module, you add the build.gradle which in the module, add the dependencies like this,
compile 'com.android.support:support-annotations:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
//recyclerview
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
you might be see this stupid problem because the old project has include the jar file like android-support-v4.jar
this shit is overlay the compile(thing) so you must remove the *.jar file,
this shit takes my hole afternoon, so good luck ,my english is pool,
fogiven me please
For what it's worth I was getting this error after using Android Studio to import a project from Eclipse. In the /app/build.gradle file I had two entries in the dependencies section, it looked like this
dependencies {
compile files('libs/android-support-v13.jar')
compile files('libs/android-support-v4.jar')
}
I removed the reference to v4 like below
dependencies {
compile files('libs/android-support-v13.jar')
}
I cleaned the project and was able to build my APK. I don't know if this was the correct way to fix it but it worked for me.
I just installed gradle in this folder:
/Users/joanet/Development/gradle-2.3
edit the file launchd.conf
sudo vim /etc/launchd.conf
to set the variable GRAILS_HOME
setenv GRAILS_HOME /Users/joanet/Development/gradle-2.3
then I've imported the project https://github.com/NordicSemiconductor/Android-nRF-Toolbox
using File -> Import project
but I got this error:
Gradle project sync failed and Error: Configuration with name 'default' not found in Android Studio
I have tried this https://www.youtube.com/watch?v=8RwVvZtNTaM
but it has not worked
Here the file build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
and here /app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.0'
defaultConfig {
applicationId "no.nordicsemi.android.nrftoolbox"
minSdkVersion 18
targetSdkVersion 22
versionCode 30
versionName "1.12.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':..:DFULibrary:dfu')
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/nrf-logger-v2.0.jar')
}
here settings.gradle:
include ':app', '..:DFULibrary:dfu'
and here gradle-wrapper.properties:
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
I just downloaded the project.
First look at the settings.gradle:
include ':app', '..:DFULibrary:dfu'
There is a project, ..:DFULibrary:dfu, that is not provided in the Github project.
Second, look at the app/build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':..:DFULibrary:dfu') // <-- You do not have this
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/nrf-logger-v2.0.jar')
}
The line, compile project(':..:DFULibrary:dfu') is trying to compile a project that you do not have.
Third, read the README.md:
Dependencies
In order to compile the project the DFU Library is required. This
project may be found here:
https://github.com/NordicSemiconductor/Android-DFU-Library. Please
clone the nRF Toolbox and the DFU Library to the same root folder. The
dependency is already configured in the gradle and set to
..:DFULibrary:dfu module.
The nRF Toolbox also uses the nRF Logger API library which may be
found here: https://github.com/NordicSemiconductor/nRF-Logger-API. The
library (jar file) and is located in the libs folder and a jar with
its source code in the source folder in the app module. This library
allows the app to create log entries in the nRF Logger application.
Please, read the library documentation on GitHub for more information
about the usage and permissions.
The graph in HRM profile is created using the AChartEngine v1.1.0
contributed based on the Apache 2.0 license.
The owner of the project provides you with the other project site's URL here: https://github.com/NordicSemiconductor/Android-DFU-Library.
Conclusion:
Simply do git clone https://github.com/NordicSemiconductor/Android-DFU-Library.git just like he says in his instructions in the same folder as your current project. Everything should work after that.
How to:
git clone https://github.com/NordicSemiconductor/Android-nRF-Toolbox.git
git clone https://github.com/NordicSemiconductor/Android-DFU-Library.git
Rename Android-DFU-Library to DFULibrary. (mv Android-DFU-Library DFULibrary)
You should be all set!
Good day, i am following this tutorial http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part5 where you have to use HttpTransport but for some reason, android-studio does not seem to find it. I have imported the libraries (some even unnecessary) that are needed but no success. here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.+'
compile 'com.google.http-client:google-http-client-android3:1.9.0-beta#jar'
compile 'com.google.http-client:google-http-client:1.17.0-rc#jar'
compile 'com.google.http-client:google-http-client-android:1.17.0-rc#jar'
compile 'com.google.code.gson:gson:2.1#jar'
compile 'com.fasterxml.jackson.core:jackson-core:2.1.3#jar'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.4#jar'
compile 'com.google.code.findbugs:jsr305:1.3.9#jar'
compile 'com.google.protobuf:protobuf-java:2.2.0#jar'
compile 'com.google.http-client:google-http-client:1.10.3-beta#jar'
compile 'com.google.http-client:google-http-client-android2:1.10.3-beta#jar'
compile 'com.google.http-client:google-http-client-android3:1.10.3-beta#jar'
compile 'com.google.http-client:google-http-client:1.10.3-beta#jar'
compile 'com.google.api-client:google-api-client:1.10.3-beta#jar'
compile 'com.google.api-client:google-api-client-android2:1.10.3-beta#jar'
compile 'com.google.oauth-client:google-oauth-client:1.11.0-beta#jar'
compile 'com.google.guava:guava:11.0.1#jar'
}
anything am not importing or what could be wrong?.. many Thanks in Advance.
Though late, still writing wondering if can help other developers...
The HttpTransport class resides in google-http-client jar. As you have added this dependency in the build.gradle file as shown above, I guess either you don't have network connectivity or your gradle settings is set to offline.
You can download the jar files form https://developers.google.com/api-client-library/java/google-http-java-client/download Unzip the zipped file. Copy the required jar files to the project libs directory & add them as library.
I'm trying to add a library as a dependency but it keeps giving me this error:
Class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat.AccessibilityServiceInfoIcsImpl
has already been added to output. Please remove duplicate copies.
Execution failed for task ':BrooklynTech:dexDebug'.
Could not call IncrementalTask.taskAction() on task ':BrooklynTech:dexDebug'
Here is my 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 14
targetSdkVersion 19
}
}
dependencies {
compile files('libs/Simple-Rss2-Android.jar')
compile 'org.jsoup:jsoup:1.7.3'
compile 'uk.co.androidalliance:edgeeffectoverride:1.0.1'
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
compile project(':libraries:calendar-card')
compile 'com.twotoasters.jazzylistview:library:1.0.0' }
the dependency I added was for jazzylistview - https://github.com/twotoasters/JazzyListView
How can I fix the error?
More than one of your dependencies is including the classes from the v4 support library; you'll need to track it down. You ought to be able to open up the jar files from the project viewer and find the culprit.
Ideally none of your dependencies ought to be bundling the support library; it's the responsibility of your app's build to make sure that gets finally linked in.
Not sure, but could you try the following snippet. Maybe the transitive libs are causing the trouble
dependencies{
...
compile ('com.twotoasters.jazzylistview:library:1.0.0'){
transitive = false
}
}
cheers,
René