When I try to sync gradle, it shows this error.
Warning:Unable to find optional library: org.apache.http.legacy
My build.gradle:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.myapp.mynamespace"
minSdkVersion 15
targetSdkVersion 23
versionCode 17
versionName "1.7"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions.encoding = 'UTF-8'
}
My root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
I tried to use gradle 1.3.1 and buildToolsVersion 23.0.2 but it didn't work. There aren't many questions like this and they didn't resolved out. So I needed to ask this question to come to a fine end.
I had this problem before and the way I solved it was by copying the JAR into the libs/ folder of your project, Gradle will not resolve this jar automatically.
You should have a copy in your local machine already under SDK/platforms/android-23/optional
Related
I imported the opencv android library to my android studio and the Camera2Renderer class has a lot of compiler errors because the android.hardware.camera2 classes can't be imported.
I solved the problem. Jim was right, I did not have the correct target API. For the next person who has this problem and finds this thread, the solution is that you have to make sure that the build.gradle files for your project and your OpenCV match.
I am working with openCVLibrary3.2.0 and trying to run its sample and faced same issue but I changed gradle files for both mysampleApp and openCVLibrary320 module as below
This is my app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "org.opencv.face"
minSdkVersion 9
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
targetCompatibility JavaVersion.VERSION_1_5
}
ndk {
moduleName "native_sample"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
dependencies {
compile project(path: ':openCVLibrary320')
}
and this my OpenCV library module build.gradle file
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Note:
things to notice are that compileSdkVersion, buildToolsVersion, minSdkVersion, and targetSdkVersion these must be same for all gradle files
I changed the compileSdkVersion from 14 to 23
and buildToolsVersion to "23.0.2"
this solved the camera2 import related issue
I am working on openCVLibrary330 trying to run its sample and faced same issue but i changed gradle files for openCVLibrary330 module as below
This is my app build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
I had the same problem. But, as many people have suggested I didn't had to change the gradle files to match exactly the same. I changed my compileSdkVersion and buildToolsVersion to the same on both gradle files, the rest are different. Its working fine now.
I'm getting mad, after updating android studio 2.2 to 2.3 i can't create and edit any project because gradle get error:
Failed to find build tools revision 26.0.0 or any versions
I downloaded Gradle and build tools from android studio also but didn't work.
My gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "atys.myapplication"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
and:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
}
You Should Update Your Tools with the SDK Manager First .
Look This Link Its Helpful.
https://developer.android.com/studio/intro/update.html
if your problem do not solve. uninstall your android studio and Delete you Sdk Folder and reinstall android studio new Version from this link:
https://developer.android.com/studio/index.html
I'm a newbie with gradle and I'm having a dependecy problem. I have the follow project structure:
-MyApp
-MyAppLibrary
-MyAppPro
-MyAppFree
-ThirdPartyLibraryWrapper
--libs\ThirdPartyLibrary.aar
Both MyAppPro and MyAppFree depend on MyAppLibrary, which depends on ThirdPartyLibraryWrapper. As the name suggests, ThirdPartyLibraryWrapper is a wrapper on an external library, namely ThirdPartyLibrary.aar.
This is my configuration:
build.gradle MyAppPro
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example"
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':MyAppLibrary')
}
build.gradle MyAppLibrary
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
compile project(':ThirdPartyLibraryWrapper')
compile 'com.squareup.picasso:picasso:2.5.2'
}
build.gradle ThirdPartyLibraryWrapper
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ThirdPartyLibrary-0.1.0', ext: 'aar')
compile "com.android.support:support-v4:22.0.0"
compile fileTree(dir: 'libs', include: 'volley.jar')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
}
When gradle sync completes, I have got this error:
MyApp/MyAppFre/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppLibrary/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
MyApp/MyAppPro/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
Can someone help me figure out where is the issue?
The other projects are seeing that the :ThirdPartyLibraryWrapper project depends on an artifact called ThirdPartyLibrary-0.1.0:aar. Java (and Android) libraries do not bundle their own dependencies together - instead, they simply publish a list of their dependencies. The consuming project is then responsible for loading not only the library it directly depends on, but all of the libraries that library depends on.
The net effect of this is that :MyAppFree is loading in :ThirdPartyLibraryWrapper, then seeing that :ThirdPartyLibraryWrapper depends on ThirdPartyLibrary-0.1.0:aar and so thus trying to load that in as well. However, :MyAppFree doesn't know where ThirdPartyLibrary-0.1.0:aar lives.. and so it fails.
The solution will be to place similar repositories blocks in all your other projects. Try this:
repositories {
flatDir {
dirs project(':ThirdPartyLibraryWrapper').file('libs')
}
}
Using the project(...).file(...) method will free you from having to hardcode paths, and will instead use the Gradle DSL to resolve the filesystem path by looking up the project and having it do the resolution dynamically.
Getting the following error when building the project:
Error:(2, 0) Android tasks have already been created.
This happens when calling android.applicationVariants,
android.libraryVariants or android.testVariants.
Once these methods are called, it is not possible to
continue configuring the model.
Root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'android'
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion '19.1.0'
defaultConfig {
versionCode 5
versionName '5'
targetSdkVersion 19
minSdkVersion 10
applicationId 'tsp.movil'
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:support-v4:22.1.1'
}
App build.gradle:
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "tsp.movil"
minSdkVersion 10
targetSdkVersion 19
versionCode 5
versionName '5'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/zbar.jar')
}
Your Top Level build.gradle file should only have the configuration common for all modules of your project.
make the following changes :
Root build.gradle file should have only this piece of code
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects{
repositories {
jcenter()
}
}
I've faced a similar issue, with the same error message. The issue in my case was that I've had created a module inside a package and then deleted it manually in (MacOS) Finder.
The problem was that I forgot to also remove the include ::myModule line from the settings.gradle file.
look on this:
How to define common android properties for all modules using gradle
the 3rd comment says Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants. Once these methods are called, it is not possible to continue configuring the model.
I'm getting the following error in Android Studio 0.4.2 when I'm trying to Sync project with gradle.
Gradle 'GooglePlayServicesTest' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'android()'!
My projects gradle file is as follows :-
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
android{
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
sourceSets{
main{
manifest.srcFile 'GooglePlayServicesTest/src/main/AndroidManifest.xml'
}
}
}
gradle file of module:-
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
also I have removed the miniSDKVersion and targetSDKVersion from AndroidManifest.xml
can someone help me to solve this error.
android method in project gradle file is not needed.Try to remove it.
Add top of your project build.gradle file:
apply plugin: 'com.android.application'