I have been following the Android fragments tutorial which requests that I set up my project to work with the v4 library by following the Support Library Setup document here.
Here are the steps I followed.
1) Make sure you have downloaded the Android Support Repository using
the SDK Manager.
2) Open the build.gradle file for your application.
3) Add the support library to the dependencies section. For example,
to add the v4 support library, add the following lines:
dependencies {
...
compile "com.android.support:support-v4:24.1.1"
}
After following the three steps I receive these two errors:
Gradle project sync failed...
Error:Could not find method compile() for arguments [com.android.support:support-v4:24.1.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Please install the Android Support Repository from the Android SDK Manager.
According to the Android SDK Manager, I do have the Android Support Repository installed.
I am going to continue investigating this issue as fragments appear to be a valuable tool to develop powerful Android mobile apps. Help approaching this issue would be appreciated.
As Sufian requested in the comments below, here are the contents of my build.gradle file.
// 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.3'
compile "com.android.support:support-v4:24.1.1"
// 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
}
Here is a screenshot of my Android Standalone SDK Manager showing that the Android Support Repository is installed.
There are two build.gradle files in your project, one rootlevel, and one for your application. You will also see a dependencies section in the other build.gradle. You need to place the compile "com.android.support:support-v4:24.1.1" in there.
You are adding compile "com.android.support:support-v4:24.1.1" in <PROJECT_ROOT>\build.gradle instead you should add the above dependency in <PROJECT_ROOT>\app\build.gradle
Related
Duplicate class android.support.design.widget.CoordinatorLayout found in modules design-25.3.1-runtime (com.android.support:design:25.3.1) and support-core-ui-27.1.1-runtime (com.android.support:support-core-ui:27.1.1)
I encountered this error and decided to post it as a question with a solution for anyone who might run into this.
Approaches
There are some approaches to fix this
Adding Support Libraries
Re-Installing SDK build-tools
Adding Support Libraries
In order to use a Support Library, you must modify your application's project's classpath dependencies within your development environment. You must perform this procedure for each Support Library you want to use.
To add a Support Library to your application project:
Include Google's Maven repository in your project's build.gradle file.
allprojects {
repositories {
google()
// If you're using a version of Gradle lower than 4.1, you must
// instead use:
//
// maven {
// url 'https://maven.google.com'
//}
}
}
For each module in which you want to use a Support Library, add the library in the dependencies block of the module's build.gradle file. For example, to add the v4 core-utils library, add the following to your dependencies:
dependencies {
implementation "com.android.support:support-core-utils:28.0.0"
}
To Re-install build-tools
Go to the SDK manager, click the "SDK Tools" tab. If the check-mark for "Support Repository" is selected, unselect it and click OK. This will delete all of the files in the repository. Then recheck the check-mark, click GO and reinstall the repository.
Links
Support Library Setup
Add build dependencies
I want to add AdView to my activity and I click on download and then it automatically implements the necessary library. But then I get the following error:
Error 1
I get the same error when I try to add GridLayout to my library.
Here is my gradle file: gradle file
I already tried to set the Global Gradle settings to offline work but it doesn't help.
I have android studio 3.4.2
This is a problem that bothers me for a while now and there seems no solution to this. Is it possible that these things are not available for androidx yet? Thank you for your help!
From the documentation:
To make the Google Play services APIs available to your app:
Open the build.gradle file inside your application module directory.
Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.
Add a new build rule under dependencies for the latest version of play-services, using one of the APIs listed below.
Ensure that your top-level build.gradle contains a reference to the google() repo or to maven { url "https://maven.google.com" }.
Save the changes, and click Sync Project with Gradle Files in the toolbar.
You can now begin developing features with the Google Play services APIs.
This is often a common mistake. If you have multiple repositories in your gradle, make sure that maven google is at the top of the list.
eg.
repositories {
maven { url "https://maven.google.com" }
...
}
This package:
// https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads
implementation "com.google.android.gms:play-services-ads:18.1.1"
is either available from repository google() or from repository mavenCentral():
repositories {
google()
mavenCentral()
...
}
see the quick-start.
I want to include the material-design library for android into my project, but I'm a bit confused where to find it and how to include it. I downloaded the library from github https://github.com/material-components/material-components-android.
I tried to build it with gradle, but I got the following error, to which I can't seem to find the solution:
> Configure project :catalog
Checking the license for package Android SDK Build-Tools 27.0.3 in /mnt/sda2/android/Sdk/licenses
Warning: License for package Android SDK Build-Tools 27.0.3 not accepted.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':catalog'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;27.0.3 Android SDK Build-Tools 27.0.3
I have the 'build-tools 27.0.3' installed through the SDK manager. Any hints please on how can I bypass this issue?
As far as I understood, I need to compile the library in the first place, then place it into the /lib folder, and then tell 'Ant' build tool to include this library in order to use it. Is this correct? Maybe there's a place from which I can simply download already pre-compiled lib? I couldn't seem to locate it in the SDK manager. Thank you!
I'm trying to build the project with Gradle now, this is my build.gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
implementation 'com.google.android.material:material:1.0.0-beta01'
}
}
allprojects {
repositories {
google()
jcenter()
mavenLocal()
}
}
but I keep getting an error:
Could not find method implementation() for arguments [com.google.android.material:material:1.0.0-beta01] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Any hints please?
UPDATE
I downloaded android studio, followed the instructions, here's a snippet of my build.gradle:
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
compile "com.android.support:design:27.1.1"
}
but now I'm getting a different error:
Could not find method compile() for arguments [com.android.support:design:25.1.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
I opened the SDK manager, but he Android Support Repository is already installed (rev47). Any hints please? Thanks!
Make sure your compiledSdkVersion is 28
In build.gradle, make sure that the repositories section includes Google's Maven repository google()
i.e.,
add this
allprojects {
repositories {
google()
jcenter()
}
}
Then, add the dependencies.
dependencies {
implementation 'com.google.android.material:material:1.0.0'
}
Then Refactor to AndroidX.
Click on Refactor and then click on Migrate to AndroidX.
Then it will update your app's dependencies and code to use the newly packaged androidx and com.google.android.material libraries.
or
You can use com.android.support:design:28.0.0 dependency if you do not wish to switch to androidx.
Note: You cannot use both com.android.support and com.google.android.material dependencies in your app at the same time.
Hope following things help you :-
**A problem occurred configuring project ':catalog'.Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;27.0.3 Android SDK Build-Tools 27.0.3**
You need to accept the licence first, check the link here for your licence issue :- https://stackoverflow.com/a/41078173/2919483
For adding material design library in Android studio :-
In you build.gradle, add the dependency like:
dependencies {
compile 'com.android.support:design:25.1.0'
}
sync your project and start using that.
So I'm trying to transfer to android studio but I've been getting this error all the time.
This is the only thing I'm getting in the log:
Error:Could not find method compile() for arguments [com.android.support:support-v4:20.0.0] on
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#50a8e746.
Please install the Android Support Repository from the Android SDK
Manager. Open Android SDK Manager
The problem is that I have android support repo installed as well as pretty much everything else so I really don't have any idea how to fix this.
I've even tried deleting the .gradle and let it download again but it didn't fix anything.
Here's my build.gradle (I did make changes to it since I was getting a build error):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
// do not use dynamic updating.
compile 'com.android.support:support-v4:20.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Android SDK:
Don't put module-level dependencies in the buildscript block. The buildscript block is for dependencies for the build system itself, i.e. if you were adding more Gradle plugins. To add dependencies for your modules, place them in the build.gradle file in the module directory.
I'm using Android Studio on Arch Linux and I installed the Support Repository using the SKD Manager. However whenever I try to use it I get an error saying:
Error:Could not find method compile() for arguments [com.android.support:appcompat-v7:19.1.0] on root project 'Aaaa'.
Please install the Android Support Repository from the Android SDK Manager.
I tried appcompat v7, support v4 and support v13 (I checked all of them are installed). I tried running as root and I still get the same error. The path in local.properties is pointing to the right directory. I'm no really sure what else I should change.
I created a blank activity just to try and use this repository, here is the build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.1.0'
}
You've put your dependencies block in the wrong build.gradle file. Instead of the top-level build file, put it in your module's build file instead.