I just installed the new Android Studio and I'm looking for a way to import the support library for Android.
Where is the option for that? In Eclipse that are just two clicks. I googled for it but found nothing. Surely it is too new.
=============UPDATE=============
Since Android Studio introduce a new build system: Gradle. Android developers can now use a simple, declarative DSL to have access to a single, authoritative build that powers both the Android Studio IDE and builds from the command-line.
Edit your build.gradle like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 18
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.+'
}
NOTES: Use + in compile 'com.android.support:support-v4:21.+' so that gradle can always use the newest version.
==========DEPRECATED==========
Because Android Studio is based on IntelliJ IDEA, so the procedure is just same like on IntelliJ IDEA 12 CE
1.Open Project Structure (Press F4 on PC and Command+; on MAC) on your project).
2.Select Modules on the left pane.
3.Choose your project and you will see Dependencies TAB above the third Column.
4.Click on the plus sign in the bottom. Then a tree-based directory chooser dialog will pop up, navigate to your folder containing android-support-v4.jar, press OK.
5.Press OK.
I no longer work on Android project for a while.
Although the below provides some clue to how an android studio project can be configured, but I can't guarantee it works flawlessly.
In principle, IntelliJ respects the build file and will try to use it to configure the IDE project. It's not true in the other way round, IDE changes normally will not affect the build file.
Since most Android projects are built by Gradle,
it's always a good idea to understand this tool.
I'd suggest referring to #skyfishjy's answer, as it seems to be more updated than this one.
The below is not updated
Although android studio is based on IntelliJ IDEA, at the same time it relies on gradle to build your apk. As of 0.2.3, these two doesn't play nicely in term of configuring from GUI.
As a result, in addition to use the GUI to setup dependencies, it will also require you to edit the build.gradle file manually.
Assuming you have a Test Project > Test structure.
The build.gradle file you're looking for is located at TestProject/Test/build.gradle
Look for the dependencies section, and make sure you have
compile 'com.android.support:support-v4:13.0.+'
Below is an example.
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.+'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
You can also add 3rd party libraries from the maven repository
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
The above snippet will add gson 2.2.4 for you.
In my experiment, it seems that adding the gradle will also setup correct IntelliJ dependencies for you.
This is way more simpler with Maven dependency feature:
Open File -> Project Structure... menu.
Select Modules in the left pane, choose your project's main module in the middle pane and open Dependencies tab in the right pane.
Click the plus sign in the right panel and select "Maven dependency" from the list. A Maven dependency dialog will pop up.
Enter "support-v4" into the search field and click the icon with magnifying glass.
Select "com.google.android:support-v4:r7#jar" from the drop-down list.
Click "OK".
Clean and rebuild your project.
Hope this will help!
You can simply download the library which you want to include and copy it to libs folder of your project. Then select that file (in my case it was android-support-v4 library) right click on it and select "Add as Library"
In Android Studio 1.0, this worked for me :-
Open the build.gradle (Module : app) file and paste this (at the end) :-
dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}
Note that this dependencies is different from the dependencies inside buildscript in build.gradle (Project)
When you edit the gradle file, a message shows that you must sync the file. Press "Sync now"
Source : https://developer.android.com/tools/support-library/setup.html#add-library
Android no longer downloading the libraries from the SDK manager, it has to be accessed through Google's Maven repository.
You will have to do something similar to this in your build.gradle file:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
dependencies {
...
compile "com.android.support:support-core-utils:27.0.2"
}
Find more details about the setting up process here and about the different support library revisions here.
AndroidX[About]
implementation 'androidx.appcompat:appcompat:1.0.2'
Related
I have created Android library as Android Studio module. Added as dependency to my root module. While coding I can import any class from library package but while I'm trying run the application I'm getting an error package some.mylibrary.project does not exist.
build.gradle root module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:5.+'
compile project(':libraries:mylibrary')
}
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
abortOnError false
}
***
}
build.gradle library module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'idea'
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
*****
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
settings.gradle
include ':libraries:mylibrary'
P.S. I have to mention that the project was exported from Eclipse IDE so the project structure is different from default one.
For Android Studio 2.2.2
Yes, in library module, it can't use the apply plugin: com.android.application statement in the module definition, yes, use apply plugin: com.android.library instead. (still in lib module)
But then you have to do the following:
Expose the same SDK versions in Gradle files for both modules.
Right click on your projects "app" module folder and click on -> open module settings
Click on the "dependencies" tab
Click on the + sign to add a new dependency and select "Module Dependency"
Look for the library you need and add it.
Also while naming your lib module avoid capitals.
If you have a library module, it can't use the apply plugin: 'com.android.application' statement in the module definition, or the build will silently fail as you're seeing. use apply plugin: 'com.android.library' instead.
A bug has been filed to request that the build system fail loudly instead of silently when this happens: https://code.google.com/p/android/issues/detail?id=76725
The answer above is somewhat lacking
If you project java add in Kotlin getting get this error
Tools Tab Kotlin and Configure Kotlin
(Select Android with Gradle) after select with Modules
Project build.gradle add
ext.kotlin_version = ‘1.3.21’
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Apps build.gradle
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Referance : https://medium.com/mindorks/enabling-kotlin-support-for-a-current-only-java-android-project-98c75e04384a
This error happens when you change the package name and try to run the code. this occurs because the android studio still has the cache of your package with an old name.
Also, cross-check all the imports as well as an imported package in your code so that no different package name exists. For example, is common this error is referring to another imported file near where the error is occurring. Check previous imports near.
To fix this error you can try to do an 'invalidate caches / Restart' option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.
Another reason for this error, is when one changes the project's path root folder or in any of the modules it depends. In this particular case, to fix this error you need to remove the affected modules, and re-add them again. Next don't forget to do an 'invalidate caches / Restart' option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.
Clean your project from android studio :
“Build -> Clean Project”. This will clear your build folders.
Remove your .gradle directory from the root of your project. It contains some Gradle cache files.
Delete also the .idea directory (make a backup before). It contains some project configuration files.
Restart Android Studio.
Finally
if the error still persists, you need to move the affected files to an external directory of the project's root folder. And on Android Studio, create manually each filename as previous, and copy the code inside from the old file. This will defiantly solve this error.
In build-gradle app, add this row:
implementation project(":your_name_library_here")
If you are facing this issue while using Kotlin and have
kotlin.incremental=true
kapt.incremental.apt=true
in the gradle.properties, then you need to remove this temporarily to fix the build.
After the successful build, you can again add these properties to speed up the build time while using Kotlin.
Reference: https://stackoverflow.com/a/58951797/3948854
I want to build an app in Android Studio with the support library but I get the following error when adding the dependency for the support library:
Error:Failed to find: com.android.support:support-v4:19.1.0
Here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '20'
defaultConfig {
applicationId "sample.myapplication"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.0'
}
I have downloaded the support library via the sdk manager.
Ok, found the problem. The Android support repository was missing. After installing and restarting Android Studio it worked.
If you are using Android Studio, then as an addition to changing the build.gradle file manually, you can also lookup the dependency via the library dependencies under the Project Structure menu item.
Double clicking that dependency will generate this line in build.gradle:
dependencies {
compile 'com.android.support:support-v13:+'
}
And also, if you are wondering what this library is about, it's described at the developer pages at developer.android.com; Support Library.
My Android Studio version is 1.1. I select tools->Android->SDK Manager, check the Android Support Library then click Install packages, solved this issue.
In my case the solution was as simple as running Build:Make Project. No amount of gradle syncing or clearing caches would do it. Of course, that required getting my project into a state where it would build successfully.
In my case I needed to add Google Maven repository.
It shows as part of the error in Android Studio and only needed to click on it to add itself.
Then Gradle built the project on its own.
Following the instruction here helped me. For whatever reason when I had to reinstall the latest version of android studio the initial download of the extras section android support library failed. I simply retried it. Followed the steps mentioned and verified it was added to the build.gradle file and did a rebuild project and good to go.
http://developer.android.com/tools/support-library/setup.html
So my coworker uploaded a project to GitHub which i pulled. I expected everything to be okay, but for some reason it won't load v7 support library (it gives sqiggly red lines under the v7 import)
Does anyone know how to solve this?
EDIT:
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.0'
}
Make sure the Android Support Repository is installed in your SDK manager:
In eclipse, you have to import the support libraries into your workspace by clicking "file" "import" and then browsing to wherever the SDK lives on your computer ... adt-bundle-windows-x86_64-20131030>sdk>extras>android>support>v7 (for the root directory). Then some projects should appear in the "Projects to import" window. Select the ones you need and then select "finish". Once they are in your work space, select your project that needs them and right click it and select "properties". Then a window pops up. Select "Android" on the left and then in the bottom box select the v7 support libraries that you need and select "add", then "OK." Now you have to rebuild your project and the red squiggly lines should go away. Yay!
I need help installing/implementing ActionBarSherlock 4.4.0 into Android Studio 0.2.3. I have tried multiple tutorials and looked through answers on here. But none have worked for this beginner.
Has anyone tried to install ABS 4.4.0 into Android Studio yet? Can anyone give me detailed step by step instructions on how to do this? Or point me to an answer or tutorial that will help?
I successfully added it as aar dependency, no need to download and compile any sources.
Open Tools -> Android -> SDK Manager and install latest platform and build tools 18.0.1.
Create new project with Android Studio for Android 2.1 (API level 7) and replace build.gradle of subproject (not the top one) with the one below.
Complete minimal build.gradle, it needs Android Build Tools version 18:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 18
}
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
If you are already using Android Studio, you might do it the GUI way.
This also allows you to search the Maven repo, so if you don't know the full name of the
library no worries.
Press CTRL+ALT+SHIFT+S
Select the module
Click Dependencies
Click the green arrow
Input sherlock and press enter to search
Select com.actionbarsherlock:actionbarsherlock:4.4.0#aar
This will automatically add it to your build.gradle
I am trying to use this library [1] in an Android project either with Android Studio or with ADT. But it doesn't work at all. In ADT I don't know how to handle gradle stuff and in Android Studio, when I try to "Import Project", I get the error "Could not find com.google.android.gms:play-services:3.1.36.
(don't have enough reputation to post picture, it's on imgur with xswZ3.jpg)
I am not familiar with gradle and I only have a vague idea of what it does but all I want is to use something like BubbleIconFactory f = new BubbleIconFactory(this) in my own project.
Any help is appreciated!
[1] https://github.com/googlemaps/android-maps-utils
Perhaps your problem is needing the repositories outside of the buildscript block.
The repositories internal to the buildscript is for managing the gradle dependency itself, I believe. Here's how I resolved my problem with google-maps-utils as a library dependency. Hopefully this helps. I included my maps and support-v4 libs too.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.2+'
}
You'll need to install the "Google Repository" from the Android SDK manager.
See demo/build.gradle for an example.
You can, of course, copy the library directory and use it like any other Android library project.
Let me know if this helps!
Chris
Steps:
First File>Project Structure>Click Plus Button >Import Graddle Project>Select the file(library folder) from the location where downloaded>CLick Ok.
Add this code to dependencies to that app module build.gradle file(remember there are two build.gradle files) :
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Copy gradle.properties file contents of that Android-maps-util Library project app(found inside that project library folder) TO
gradle.properties file of your project(Simple copy and paste of content to the editor).
Click Sync Project with gradle files button. And you must be fine!