Adding support library to android studio project - java

I am trying to add v7 support for action bars to my project and followed the steps on the android dev site but still doesn't work...
In my gradle file I have
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile "com.android.support:appcompat-v7:18.0.+"
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
just like it says to do but when I try to import the class or use the resource, it isn't found.
I also downloaded the latest support library and repository in the sdk manager as well.
Am I missing a step or setting?

I fixed it.... All I needed to do was run
./gradlew clean build
in the root of my project. Android studio wasn't updating the gradle so it didn't include the external libraries.

Related

ERROR: Gradle DSL method not found: 'imlementation()'

My app is not working after I updated my android phone to Android 10. So I migrated my app to androidx. Now I am trying to update my gradle from 2.3.1 to 3.5.1.
This is my build.gradle(Project:) file -
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
My build.gradle(Project:) file is -
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "....."
minSdkVersion 19
targetSdkVersion 29
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
imlementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation files('....')
implementation files('....')
implementation files('....')
implementation files('....')
}
This is the Error I get -
ERROR: Gradle DSL method not found: 'imlementation()'
Possible causes:
The project '.....' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0). Upgrade plugin to version 3.5.1 and
sync project
The project '...' may be using a version of
Gradle that does not contain the method. Open Gradle wrapper file
The build file may be missing a Gradle plugin. Apply Gradle plugin
I am new to android development. I am using android studio.
Thank you in advance.
You made a typo in your first implementation declaration. imlementation -> implementation.
Change imlementation
to
implementation

How do I determine which Android Gradle Plugin version is needed for my target SDK?

I am trying to sync my project with the Gradle files but every time I do it I get the same error message:
WARNING: The specified Android SDK Build Tools version (27.0.0) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
My target SDK version is API 24 since I am developing an app for an Android 7.0 (Nougat) operating system.
I looked over the Android Developers site: https://developer.android.com/ and I can't find anything about what Android Gradle Plugin corresponds with which target SDK version. I've read several Stack Overflow questions where people asked about which specific Android Gradle Plugin they need for their project but none of the questions were about where to go to find that information.
Can anyone tell me how to know which Android Gradle plugin version I need?
Here are the two build.gradle files in my app folder:
(Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '27.0.0'
defaultConfig {
applicationId "com.android.example.favoritetoys"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
debuggable true
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
}
(Project)
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
}
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Since AGP (Android Gradle Plugin) version 3.0.0, there is a minimum version requirement for the Android Build Tools version, which is a designed behaviour.
See
http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.AppExtension.html#com.android.build.gradle.AppExtension:buildToolsVersion
So, if you want to force your project to use an older version of build tools, i am afraid that you need to downgrade your AGP to a version below 3.0.0.
But, question for you is why do have to use the older build tools?
As seen from https://developer.android.com/studio/releases/build-tools.
You should always keep your Build Tools component updated by
downloading the latest version using the Android SDK Manager.
For your cross reference about the differences among the three different version configurations in build.gradle, i.e. compileSdkVersion, targetSdkVersion and minSdkVersion.
What is the difference between compileSdkVersion and targetSdkVersion?
What is the difference between min SDK version/target SDK version vs. compile SDK version?
For your case, maybe you only need to change your targetSdkVersion to 28.

gradle sync failed after install official Android Studio 3.0 with strange errors [duplicate]

i try to add recyclerview to my project and get this error appear and i added it from android studio dependencies
Starting from version 26 of support libraries make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint.
Something like;
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
This is how I have it working.
Add maven { url "https://maven.google.com" } as #Gabriele_Mariotti suggests above.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Then on the build.gradle file inside the App folder add
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 16
targetSdkVersion 26
}
Then on the dependencies use
dependencies {
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:cardview-v7:26.0.1'
}
If you are using Android Studio 3.0 or above make sure your project build.gradle should have content similar to-
buildscript {
repositories {
google() // add google() before jcenter()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google() // add google() before jcenter()
jcenter()
}
}
And for below Android Studio 3.0 and starting from support libraries 26.+ your project build.gradle must look like this-
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Note- position really matters add google() before jcenter()
check these links below for more details-
1- Building Android Apps
2- Add Build Dependencies
3- Configure Your Build
Just add this to your main all project level build.gradle file under allprojects()
maven {
url "https://maven.google.com"
}
I face the same problem while I have updated my SDK and Android studio version(3.0 beta). I have solved this problem going through this tutorial. In this they told us to update are build configuration file like
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
targetSdkVersion 26
}
...
}
dependencies {
compile 'com.android.support:appcompat-v7:26.0.0'
}
// REQUIRED: Google's new Maven repo is required for the latest
// support library that is compatible with Android 8.0
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Hope it will help you out.
in may case I found OneSignal changed their dependencies
so I changed it from
compile 'com.onesignal:OneSignal:[3.5.8, 3.99.99]'
to
compile 'com.onesignal:OneSignal:[3.5.8, 3.5.8]'
then it works, please check any unspecific dependency.
Add this to the project level build.gradle file and it should work fine.
allprojects {
repositories {
google() // this is to be added if there's something already.
jcenter()
}
}
Google's new Maven repo is required for the latest support library that is compatible with Android 8.0.
Just update your Google's Maven repository like below:
To add them to your build, add maven.google.com to the Maven repositories in your module-level build.gradle file:
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Alternative you can update build.gradle file like this:
repositories {
jcenter()
google()
}
Then add the desired library to your dependencies block. For example, the cardview library looks like this:
dependencies {
compile 'com.android.support:cardview-v7:26.1.0'
}
in sdk 28
u can use
implementation 'com.android.support:design:28.0.0'
and remove cardView library
Update your Android Support Repository from sdk manager.
There is another way to add google repository
Add gradle-4.1-rc-1-all in gradle-wrapper.properties.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
Then add google() in the top-level build.gradle
allprojects {
repositories {
google()
jcenter()
}
}
Simply change the build-version from
compile 'com.android.support:appcompat-v7:26.0.0'
to
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
This will solve your problem.
If the other solutions here do not work, make sure you are not in 'offline' mode. If enabled, android will not download the required files and you will get this error.
try to compile
compile 'com.android.support:cardview-v7:25.3.1'
Clean your gradle from terminal
./gradlew clean
then use this code in your build.gradle section
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Make sure, your included library version is available. For your checking, you can use this link
I had this issue when creating a new project in Android Studio using Kotlin. The way that finally helped me:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
google()
jcenter()
}
}
Ionic 4, opened /platforms/android/platform.properties, changed the version of the listed library throwing the error (in my case, com.android.support:support-v4:27.+) to:
com.android.support:support-v4:28.+
Use compile 'com.android.support:cardview-v7:25.4.0'
If you want version 26 you should use compile 'com.android.support:cardview-v7:26.0.0-beta2', because it is beta for now
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.test"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
this is working for me
compile 'com.android.support:cardview-v7:+'
This should pull the most recent version, and allow it to compile.
try this,
goto Android->sdk make sure you have all depenencies required . if not , download them . then goto File-->Settigs-->Build,Execution,Depoyment-->Gradle
choose use default gradle wapper (recommended)
and untick Offline work
gradle build finishes successfully for once you can change the settings
May be this problem is due to facebook library.
Replace
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
by
compile 'com.facebook.android:facebook-android-sdk:4.26.0'
#Aryan is correct Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error)
A picture worth thousand words
2 Steps to fix this..
1, connect to internet.
2, Click on clean project. this will fix it
:)
For me I just had to clean my project.
Build -> Clean Project
Another time I had to:
File -> Sync Project with Gradle Files.
When you sync this dependency to the android studio:
implementation 'com.android.support:cardview-v7:26.0.1-alpha1'
Then, Sync the Gradle with Project Files.
It will say, (Suppose if you are working on new ones like androidx) obviously, it will show error on the dependency.
For that you can go to the File menu and click on the invalidate/restart the code. It will resolve itself and the application will restart without any error.

spoon gradle : Could not create plugin of type 'AppPlugin'

my gradle project was build succeed, but when add spoon ,then i got this error (Could not create plugin of type 'AppPlugin')
my gradle version 1.9
build.gradle :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.9.+'
}
}
apply plugin: 'android'
apply plugin: 'spoon'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
instrumentTestCompile 'com.squareup.spoon:spoon-client:1.0.5'
}
The minimum supported version Android plugin is 0.8. However there is no good documentation against what Spoon plugin version should be used with what version of Android plugin at the moment.
I recommend using the latest versions of both plugins, which will also require newer Gradle version.
P.S.
There was a github issue raised by you: https://github.com/stanfy/spoon-gradle-plugin/issues/14. Right? :)

Android Studio 0.3.2: gradle compile problems

I just updated Android Studio to version 0.3.2. My project uses Gradle version 1.8.
On the picture below you can see that it is configured in gradle and Android Studio resolver http-async package but gradle fails with Gradle: package com.loopj.android.http does not exist
I tried already
to remove android-async-http and adding it as Library again,
to include fileTree(...) in gradle configuration file,
Rebuilt project but nothing helped
Though if absolute path is set gradle works just fine.
Gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 18
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:13.0.0'
compile 'com.android.support:support-v13:13.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
compile files("libs/android-async-http-1.4.4.jar")
}
Can anyone help me with this?
Try to move the libs folder at the same level of src folder.
Android Studio have just released 0.3.7, which claims to have solved a lot of gradle issues such as adding .jar libraries
http://tools.android.com/recent
Hopefully this will help you!

Categories