Can't import project to android studio - android

I'm trying to use this library
I've added
compile 'net.rdrei.android.dirchooser:library:2.0#aar'
to dependecies.
My top level build file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And it gives me error "failed to refresh gradle project" with reference to the project, that I'm trying to import.

This library is not on Central Maven as aar.
Check here:
http://search.maven.org/#search%7Cga%7C1%7Cnet.rdrei.android.dirchooser
it is an apklib format.
I've checked the snapshots repo, and here you can find this library.
https://oss.sonatype.org/content/repositories/snapshots/net/rdrei/android/dirchooser/library/
To use the snap repo you have to change your script:
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
Then add you depencency, for example
compile 'net.rdrei.android.dirchooser:library:2.1-SNAPSHOT'

The answer provided by #unify #GabrieleMariotti and #AndyJoiner is correct. However it confused be since we have two gradle files - a project level gradle and a inner gradle (where you write your dependencies). The solution is to add the code suggested by #AndyJoiner inside your inner gradle.
Since I was confused as to where to add the code, which took me an hour to figure out, I don't want it to happen to others. So, I am posting my both gradle files.
Project Level Gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Inner Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.itcse.materialdesignsearchviewlikegoogleplay"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// Add the code for repositories here
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'http://guardian.github.com/maven/repo-releases' }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
// Add the dependencies here
compile 'com.quinny898.library.persistentsearch:library:1.0.0-SNAPSHOT#aar'
}
Hope this help others in future.

This worked for me:
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
You can find the repository here
https://oss.sonatype.org/#nexus-search;quick~dirchooser

After trying the answer by Gabriele and a bit more digging, this worked for me
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'http://guardian.github.com/maven/repo-releases' }
}
dependencies {
compile 'net.rdrei.android.dirchooser:library:2.2-SNAPSHOT#aar'
}

Related

Could not resolve com.android.support:appcompat-v7:28.0.0

There are many different questions about this, but the problems there are about using v7.28.0, v7.28.+, v7.28.0.0-rc02 But when I sync my project I get this error:
Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.android.support:appcompat-v7:28.0.0.
I've checked Support library setup and followed it's instructions but it didn't help.
This is my module app
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.mobaleghan.nasimnoor"
manifestPlaceholders = [
onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
minSdkVersion 16
targetSdkVersion 28
versionCode 8
versionName "1.6.3"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.onesignal:OneSignal:3.10.3'
}
and project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
The android studio internet connection is fine as I've tested in settings and I don't know where else to look.
I even created a new project in AS 3.2.1 But I get same error.
I don't know why this happens every time I update AS!
I'm sure other answers are good and working. but mine got solved by set proxy to Freedom of Developers.
This solution is for Persians like me who suffer from strict limitations for Iranians by google.
Now my app gradle look like this:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
repositories {
maven { url 'https://maven.google.com' }
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.mobaleghan.nasimnoor"
manifestPlaceholders = [
onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
minSdkVersion 16
targetSdkVersion 28
versionCode 9
versionName "1.6.4"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:support-core-utils:28.0.0"
implementation 'com.onesignal:OneSignal:3.10.3'
}
Those repositories are there based on OneSignal documentations.
And top level build:
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
And everything is working fine.
Android project has 2 gradle files: one stored in project scope and one stored in application scope. (noted that one project can have many applications inside, but you usually have one). So you only need to swap defined repository url in those 2 gradle files.
Step 1: Remove these lines of code in your build.gradle (app)
repositories {
maven { url 'https://maven.google.com' }
}
Step 2: Add this to your build.gradle (project)
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
}
One thing you have to aware that 28.0.0 is the last stable version of android.support. So you might want to downgrade version or migrate everything to androidX.
The stable release of 28.0.0 will be the final feature release packaged as android.support. All subsequent feature releases will only be made available as androidx-packaged artifacts.
Check out this link and welcome to the new era of androidX.
Try the following:
1) Uncheck offline work from build tools:
File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Build Tools->Gradle->Uncheck Offline work option.
2) If above doesn't work then go to your project's build gradle and add the following under repositories:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
merge this part from the module's build.gradle into the root project's build.gradle:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
repositories {
maven { url 'https://maven.google.com' }
}
only keep these lines in the module's build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
android {
...
}
the root project's build.gradle should look about like this then:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
You can still use version 28.0.0 but it seems its time to migrate to Android X!
According to Support Library Documentation:
Note: With the release of Android 9.0 (API level 28) there is a new
version of the support library called AndroidX which is part of
Jetpack. The AndroidX library contains the existing support library
and also includes the latest Jetpack components.
You can continue to use the support library. Historical artifacts
(those versioned 27 and earlier, and packaged as android.support.*)
will remain available on Google Maven. However, all new library
development will occur in the AndroidX library.
We recommend using the AndroidX libraries in all new projects. You
should also consider migrating existing projects to AndroidX as well.

Could not find support-media-compat.aar

Trying Firebase to an android gradle app. As soon as I add the firebase dependency I get the following build error.
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not find support-media-compat.aar (com.android.support:support-media-compat:26.1.0).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-media-compat/26.1.0/support-media-compat-26.1.0.aar
> Could not find support-core-utils.aar (com.android.support:support-core-utils:26.1.0).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-core-utils/26.1.0/support-core-utils-26.1.0.aar
> Could not find support-compat.aar (com.android.support:support-compat:26.1.0).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-compat/26.1.0/support-compat-26.1.0.aar
> Could not find support-compat.aar (com.android.support:support-compat:26.1.0).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-compat/26.1.0/support-compat-26.1.0.aar
It looks like it's only searching jcenter. But every reference of jcenter has other repos listed to search.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:3.2.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0' // google-services plugin
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url 'https://maven.google.com'
}
}
}
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "io.nme.samples.displayingabitmap"
minSdkVersion 16
targetSdkVersion 28
versionCode 181
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
api 'com.android.support:appcompat-v7:24.2.1'
api 'com.android.support:support-v4:24.2.1'
testImplementation 'junit:junit:4.12'
dependencies {
api project(':extension-api')
api project(':haxe-firebase')
}
implementation 'com.google.firebase:firebase-core:16.0.4'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
What am I missing here?
I came across the same issue about locating libraries. However by adjusting the repositories order, this issue has been resolved.
repositories {
google()
jcenter()
// others
}
It seems that a maven site hosted by google is what we're looking for in the first place.
BTW, maven { url 'https://maven.google.com'} is used for Gradle version lower than 4.1 and google() is the newer form of that. See also this doc.
api 'com.android.support:appcompat-v7:24.2.1'
api 'com.android.support:support-v4:24.2.1'
That's your problem right there. Even without Firebase, this should've been causing issues. You're targeting and building with API 28, but your support dependencies are at API 24. Change them to use 28.0.0.
Also check your extension-api and haxe-firebase projects and make sure they're using the latest compile and SDK versions, as well as build tools version and support library versions.
You have to Replace 26.1.0 and use support library of version 28.0.0
use below
buildscript {
ext.kotlin_version = '1.2.20'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'2.3.3
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}
allprojects {
repositories
{
maven { url "https://dl.google.com/dl/android/maven2/" }
maven { url "http://jcenter.bintray.com/" }
maven { url 'https://plugins.gradle.org/m2/'}
maven { url "https://maven.google.com" }
maven { url 'https://jitpack.io' }
mavenCentral()
flatDir {
dirs 'libs'
}
}
}

Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.1 Using Android Studio 3.0.1

My gradle project will not sync and throws the following errors:
Failed to resolve:com.android.support.test.espresso:espresso-core:3.0.1
Failed to resolve:com.android.support.test:runner:1.0.1
This is not a duplicate of previous questions because I have already included maven which was the solution to this question: Android Studio can't resolve Espresso 3.0.0
Here is my gradle:
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
//classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
apply plugin: 'com.android.application'
dependencies {
compile "com.android.support:support-v4:24.2.1"
compile "com.android.support:support-v13:24.2.1"
compile "com.android.support:cardview-v7:24.2.1"
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestCompile 'com.android.support.test:runner:1.0.1'
}
// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
'main', // main sample code; look here for the interesting stuff.
'common', // components that are reused by multiple samples
'template'] // boilerplate code that is generated by the sample template process
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 25
targetSdkVersion 26
applicationId "com.example.android.mediabrowserservice"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
dirs.each { dir ->
java.srcDirs "src/${dir}/java"
res.srcDirs "src/${dir}/res"
// assets.srcDirs "src/${dir}/assets" //added to show asset folder
}
}
androidTest.setRoot('tests')
androidTest.java.srcDirs = ['tests/src']
}
lintOptions {
abortOnError false
}
}
With including the maven in the repositories, I'm not sure why else this would not be working. What can I do so that android recognizes the espresso dependencies? Thanks!
Edit: Here is the project gradle:
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
jcenter()
}
}
buildscript {
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
jcenter()
}
}
}
I'm not sure that I am suppose to add the google() and jcenter() in both blocks but the same error exist with or without them in each block
Update:
I tried downloading hamcrest and junit jar files and pointed to those two files for dependencies and that seemed to help with a few issues but I can't find espresso jar files! Still at a loss here unfortunately
This is probably because you're forgetting adding the google() maven in another dependencies block in root/project build.gradle:
buildscript {
repositories {
// this is for the classpath repository
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
// This is for your all module dependencies
// you probably forget this block.
repositories {
google()
jcenter()
}
}

Could not find com.squareup.picasso:picasso:2.5.2

I adding picasso dependencies but seem it not worked. I tried changing the version. But still useless.
This my build.gradle (module)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "bhouse.travellist_starterproject"
minSdkVersion 21
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:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:palette-v7:23.4.0'
compile 'com.squareup.picasso:picasso:2.5.1'
}
and this is my build.gradle (project)
// 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:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
The error said:
Error:(27, 13) Failed to resolve: com.squareup.picasso:picasso:2.5.1
Show in FileShow in
Project Structure dialog
Any help are welcome.
You need to add a section allprojects at the end of your main build.gradle that defines the repositories for the modules of your project:
allprojects {
repositories {
jcenter()
}
}
This will result in the following build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
According to their Github, you have to use MavenCentral to get their library so add this to your build.gradle(app) file:
repositories {
mavenCentral()
}
Resync and try again.
You need to add a maven repository from which Picasso can be downloaded. You can do that by adding this in your app module's build.gradle file:
repositories {
jcenter()
}
A good place would be just before your dependencies {} block.
In my case, I just set in the gradle.properties settings for https
systemProp.https.proxyHost=some.proxy.adress.com
systemProp.https.proxyPort=8080
so in my case, gradle.properties will be:
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=8080
Begins when I use the app,and just have a build (module) without build (app).
After I add Picasso library appears Error: (line, column) Failed to resolve: com.squareup.picasso: Picasso: 2.5.2 Show in File || Show in Project Structure dialog
as well as with the glide library
and the solution is as it says (DenisGL) is added allprojects follows:
allprojects {
repositories {
jcenter ()
}
}

Adding Spring for Android into Android Studio project

I'm trying my hand at android development for the first time, and I'd like to create an app, "MyFirstApp", that's going to make calls to REST services. I did a little research and it looks like Spring for Android is a good tool to help me with this. I've never used Spring, and I'm not very familiar with Android Studio yet, so I'm confused how I should add the dependencies for Spring into my project.
Spring's website has a piece of code they say to copy and paste into my dependencies:
dependencies {
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
}repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
I realize there's already a question posted that addresses a very similar issue, but I need help knowing EXACTLY which file to add the above code to, and EXACTLY where to do so.
I have two "build.gradle" files that were created in my project. First is
build.gradle (Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.owner.myfirstapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
Second is build.gradle(Project: MyFirstApp)
// 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.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
}repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Can anyone help show me where in these two files I should include the Spring dependency? I really appreciate any help.
Add this in build.gradle (Module: app) inside dependencies
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
Add this in build.gradle(Project: MyFirstApp) inside repositories
maven {
url 'https://repo.spring.io/libs-milestone'
}
That's it. You are good to go.
I don't know if you are behind a firewall, so this should really be a suggestion, but need to show formatted code:
Try replacing https with http here:
maven {
url 'http**s**://repo.spring.io/libs-milestone'
}
And add a url for jcenter:
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
You add the compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3' under the dependencies in build.gradle(Module:app) and then the maven block:
maven {
url 'https://repo.spring.io/libs-milestone'
}
Is put in the allprojects set of braces below the dependencies block.

Categories

Resources