Why won't Android Support Libraries work in my project? - android

Using Android Studio, I followed the steps at https://developer.android.com/tools/support-library/setup.html as acurately as I could, but it told me the following error:
Error:Could not find method compile() for arguments [com.android.support:appcompat-v7:18.0.+] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#18899229.
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
But I have already installed the Support Repository and Library! Since I also got an error saying compile doesn't belong in the dependencies block, so I changed it to classpath, and got the following, similar error:
Error:Could not find any version that matches com.android.support:appcompat-v7:18.0.+.
Required by:
:ExpenseTracker:unspecified
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
As you can see here, it still thinks the ASR isn't installed, but as the screenshot proves, it is. So what am I doing wrong here?

I think you're placing these lines in the wrong file.
They should go in the module's build.gradle file, not in the project's one (which this would seem to be, from the screenshot).
Also, the dependencies tag should not be a child of anything else. something like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
...
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-v4:18.0.+"
...
}
EDIT Did you see the comment? :)
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

My problem was that after letting Android Studio upgrade the Gradle plugin to the latest version, it had messed up the dependency section of my module's build file. It had concatenated the dependency declaration lines together (except for the lines that were mere comments). Separating the lines (placing each dependency declaration in a single line) fixed the issue.

Related

adding new dependency with api 27 cause error

after I update android studio to 3.0.0 then add api27 I couldnt create new project
because of dependency error I found that I must update my dependency the first dependency appcompat-v7:27.0.0 and I insert https://maven.google.com in build.gradle and compile "com.android.support:appcompat-v7:27.0.0"to download dependency but it cause another error could not find method for argument and ask for updating android support repository but it is also updated
my build.gradle(projre}
I'd like to forward your attention to note
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
You opened wrong build.gradle file by mistake. Open your build.gradle file from Module: app, put your compile "com.android.support:appcompat-v7:27.0.0" inside dependencies block there.
Delete the line from where you have it now.
thanks poss i get that code should be in build.gradle (module:app)
but that didn't work and caused another error unable to resolve dependency
then i saw that it use https for downloading dependencies but i only used proxy for http so i add settings for https and done

Gradle Sync failed could not find constraint-layout:1.0.0-alpha2

Problem :
Error:Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha2.
Required by:
myapp:app:unspecified
Background :
Android Studio 2.2 P 1
Support libraries for ConstraintLayout could not be installed/updated.
Just open Preferences > Appearance & Behavior > System Settings > Android and move to SDK Tools tab. Check the following fields and install.
In my case, that support libraries for ConstraintLayout were installed, but I was adding the incorrect version of ConstraintLayout Library in my build.gradle file. In order to see what version have you installed, go to Preferences > Appearance & Behavior > System Settings > Android SDK. Now, click on SDK Tools tab in right pane. Check Show Package Details and take note of the version.
Finally you can add the correct version in the build.gradle file
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
testCompile 'junit:junit:4.12'
}
The fix is to update the android gradle plugin in your build.gradle.
This should work:
classpath 'com.android.tools.build:gradle:2.2.0-alpha2'
Or you can use the latest:
classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
My problem was, that the SDK Tools updated it to the latest version, in my case it was 1.0.0-alpha9, but in my gradle dependency was set to
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
So, you can change your gradle build file to
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
Or you check "Show package details" in the SDK Tools Editor and install your needed version. See screenshow below. Image of SDK Tools
Ensure you have the maven.google.com repository declared in your module-level build.gradle file
repositories {
maven {
url 'https://maven.google.com'
}
}
2.Add the library as a dependency in the same build.gradle file:
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
I updated my android gradle plugin to 2.2.0-alpha4 and constraint layout dependency to 1.0.0-alpha3 and it seems to be working now
First I tried everything that I have read on stackoverflow...from updating gradle to XY version, to updating ConstraintLayout to XY version...I even update my SDK tools and Android Studio to the latest version...but nothing was working.
The only solution that worked for me was that I delete ConstraintLayout library from gradle and SDK, then I opened random xml layout and in Design view under Palette section search for ConstraintLayout. If you have successfully deleted library from your project then you will be able to install the library from there if you double clicked on ConstraintLayout element.
That has create next line in my app build.gradle:
'com.android.support.constraint:constraint-layout:1.0.0-beta1'
In my project build.gradle I have this:
classpath 'com.android.tools.build:gradle:2.2.2'
Android studio version 2.2.2
Alpha version is no longer available !
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Just to make sure that in studio version 2.3 you won't see a dropdown near constraint-layout in sdk tools, it will by default install the latest version
To get the desired version check the box saying show package details and boom you can now choose the desired version you want to install
gradle com.android.tools.build:gradle:2.2.0-alpha6
constraint layout dependency com.android.support.constraint:constraint-layout:1.0.0-alpha4
works for me
For me it was a completely different issue. When I installed constraint dependancy in SDK tools, the tools somehow wrote them into the wrong directory. That is
/home/${USER}/Android/Sdk/extras/+m2repository+/com/.../constraint
instead of
/home/${USER}/Android/Sdk/extras/+android+/+m2repository+/com/.../constraint
Remedy:
Just copy the 1.0.0-alpha* directories into the latter path
While updating SDK tools, a dilog box presented with Constraint layout version that is going to get installed. Note that and update your dependency based on that. In my case it was installing beta3.
I changed my dependency like below. After that it worked.
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
In my case, I had to remove the previous versions first and download the latest one instead. v1.0 stable was released on Feb 23rd.
In my case, I had a multi-module project called "app" and "sdk". The "sdk" module is the one where I had added the constraint layout library. I got the error when I tried to incorporate "sdk" into a new multi-module project called "app2". The solution was to ensure I had added the Google Maven Repository to the project-level build.gradle file for "app2". The Google Maven Repository can be added by putting "google()" under allprojects.repositories in the project-level build.gradle file:
allprojects {
repositories {
jcenter()
google()
}
}
In my case, I was using AS 2.3 and I wanted to use the currently latest ConstraintLayout 1.1.3, but the latest version in my Preferences > Appearance & Behavior > System Settings > Android was 1.0.2.
To use ConstraintLayout 1.1.3, I updated my AS from 2.3 to currently latest 3.2.1, com.android.tools.build:gradle from 2.2.2 to 3.2.1, gradle from 3.3 to 4.6 and buildToolsVersion from 25.0.0 to 28.0.3.
I also added maven { url 'https://maven.google.com' } to the Maven repositories in the project-level build.gradle file and that solved my problem.
Just as a heads up to those still searching for this.
ConstraintLayout 1.0.1 and lower have been deprecated by maven.
For a list of available constraint layouts that can be downloaded, see below:
https://maven.google.com/web/index.html?q=Constrain#com.android.support.constraint:constraint-layout
The easiest solution at the moment, is to change
implementation 'com.android.support.constraint:constraint-layout:1.0.0-beta1'
to
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
I used com.android.support.constraint:constraint-layout:1.0.0-alpha2 with classpath 'com.android.tools.build:gradle:2.1.0', it worked like charm.
Not sure if I'm too late, but in case someone has still the error after an update of ConstraintLayout and Solver over the SDK Tools, maybe this solution could help: Error:(30, 13) Failed to resolve: com.android.support.constraint:constraint-layout:1.0.0-alpha4
Its available in androidx as following package
implementation "androidx.constraintlayout:constraintlayout:2.0.0-alpha1"
Update your constraint layout dependency to the relevant version from '1.0.0-alpha2'. In my case, I changed to the following.
compile 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
I added the following script in build.gradle(app) under android & I was able to compile.
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
Similar issue solved by Reinstalling Android Studio.
i'm try constraint layout dependency update available 1,and plugin gradle alpha-6,it worked

Installing Android SQLite Asset Helper

I need to use my ready made database. Search for solution on internet did not work until I decided I will use the mentioned library found here. However, I found it hard to use the library in that installation procedures are really shallow for beginners.
I will appreciate a step by step procedure on how to use it with Android Studio. In my struggle I tried copying sources to main/libs and adding the line to gradle did not work. I use API 19 if that helps.
UPDATE
here is my build.gradle
// 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.11.+'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
}
}
trying to compile the project I get error
Error:(9, 0) No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [com.readystatesoftware.sqliteasset:sqliteassethelper:+]
Possible solutions: module(java.lang.Object)
This is an old question, but it doesn't seem to have a proper answer, and I found it while trying to install SQLiteAssetHelper myself, so I thought I should share my experience, according to the instructions found here.
Like most inexperienced Android Studio users, I thought I should Download ZIP from the GitHub repository and place it somewhere in my PC. Turns out this is not the way to Install SQLiteAssetHelper, if you are using Gradle which is a Build system integrated in Android Studio.
What you need to do is simply described in the GitHub repository Setup section. So here is a Step-by-step guide, with some additional information:
1) Make sure that your Gradle is not in Offline Mode. (In Android Studio which is currently at version 2.2.2, go to File > Settings > Build, Execution, Development > Gradle and uncheck Offline Work in case that is checked. (This is only required for your first Sync)
2) In your Android Studio Project Navigator (on the left) you should see an item entitled Gradle Scripts. Expand it, and you should find a build.gradle file. If you see two such files, there should be a comment in a parenthesis next to each one saying Project: YourProjectName and Module: App.
If you open the one saying Project: YourProjectName you should see the following comments:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
So, you should choose the one saying Module: App, at the end of which you should see something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}
At that point, you should just add the code pointed out in GitHub, like this:
dependencies {
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}
That's all. To start using it, you just have to extend the SQLiteAssetHelper class, pretty much like extending SQLiteOpenHelper.

Unresolved dependencies error in IntelliJ IDEA

So i just started working with IntelliJ and created my first project, but i get this error in the Messages make
and this in the Event log
this is the content of my my build.gradle file
Can someone please help?
Try this in your Gradle build file:
dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
}
Your one dependency (of the form groupId:artifactId:version) is not quite right. You have the version listed as just +. Instead, it needs to be 18.0.+, which specifies a release version of 18.0.0 or greater.
See here for details.

How to add Android Support Repository to Android Studio?

I'm using Android Studio with an external Android SDK. I have installed the support library and the support repository. The support repository is in:
~/Development/Tools/android/sdk/extras/android/m2repository
When I add a dependency to the support library in the build.gradle file, like:
...
repositories {
mavenCentral()
}
...
dependencies {
compile "com.android.support:support-v4:18.0.+"
}
Android Studio cannot find the support libraries (cannot resolve symbol etc) and Gradle also cannot find the libraries:
Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
> Could not find any version that matches com.android.support:support-v4:18.0.+.
Required by:
TestAndroidStudio:TestAndroidStudio:unspecified
How do I specify in Android Studio and/or the build.gradle file the location of the Android support repository?
You are probably hit by this bug which prevents the Android Gradle Plugin from automatically adding the "Android Support Repository" to the list of Gradle repositories. The work-around, as mentioned in the bug report, is to explicitly add the m2repository directory as a local Maven directory in the top-level build.gradle file as follows:
allprojects {
repositories {
// Work around https://code.google.com/p/android/issues/detail?id=69270.
def androidHome = System.getenv("ANDROID_HOME")
maven {
url "$androidHome/extras/android/m2repository/"
}
}
}
Gradle can work with the 18.0.+ notation, it however now depends on the new support repository which is now bundled with the SDK.
Open the SDK manager and immediately under Extras the first option is "Android Support Repository" and install it
Found a solution.
1) Go to where your SDK is located that android studio/eclipse is using.
If you are using Android studio, go to extras\android\m2repository\com\android\support\.
If you are using eclipse, go to \extras\android\support\
2) See what folders you have, for me I had gridlayout-v7, support-v4 and support-v13.
3) click into support-v4 and see what number the following folder is, mine was named 13.0
Since you are using "com.android.support:support-v4:18.0.+", change this to reflect what version you have, for example I have support-v4 so first part v4 stays the same. Since the next path is 13.0, change your 18.0 to:
"com.android.support:support-v4:13.0.+"
This worked for me, hope it helps!
Update:
I noticed I had android studio set up with the wrong SDK which is why originally had difficulty updating! The path should be C:\Users\Username\AppData\Local\Android\android-sdk\extras\
Also note, if your SDK is up to date, the code will be:
"com.android.support:support-v4:19.0.+"
Android Studio 3
Make sure you have the latest version of Android Studio. The support library is included by default when you create new projects. If you are adding the Support Library to a project that doesn't have it, then you just need to add a single line to your app module's build.gradle file, and then sync gradle.
build.gradle
dependencies {
...
implementation 'com.android.support:appcompat-v7:27.1.1'
}
It should just be that easy, though there may be some things to note:
Android Studio should give you a warning nowadays if the support library needs to be updated. Just update the 27.1.1 numbers that I have here to whatever it tells you to. You can also manually check what the latest revision is if you want to.
The implementation keyword replaces compile that was used in Android Studio 2.x. (What's the difference?)
There are other support library packages that you may need to include depending on what your app uses (like constraint-layout or recyclerview).
Make sure that you have the latest updates for everything in the SDK Manager. Go to Tools > SDK Manager.
Documentation
Support Library
Support Library Setup
Support Library Features
I used to get similar issues. Even after installing the support repository, the build used to fail.
Basically the issues is due to the way the version number of the jar files are specified in the gradle files are specified properly.
For example, in my case i had set it as "compile 'com.android.support:support-v4:21.0.3+'"
On removing "+" the build was sucessful!!
Instead of doing this:
compile "com.android.support:support-v4:18.0.+"
Do this:
compile 'com.android.support:support-v4:18.0.+'
Worked for me

Categories

Resources