I use the Android Studio 3.0, when I tried adding a library via Android Studio 3.0
project structure -> dependencies -> library dependency
My Android Studio is like this:
If you write down a fully-qualified dependency
(like this):com.facebook.stetho:stetho:1.5.0
When press an enter or click the 'ok'-cta, and after that, you click the 'ok' again,
Then the studio will add the dependency to your build.gradle file.
Sync your project, and that's all.
You are able to modify the scope before you add the new dependency.
Use implementation/annoitationProcessor/compileOnly/etc. as expected.
(https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations)
But, I think it is a better way to handle(add and remove) all the dependencies in the build.gradle file directly, and use this window for double-check the already used dependency.
I hope, it helps you.
Related
I am developing an android app. I have added a new project to my gradle build as follows....
In the build.gradle I have added...
android {
dependencies {
implementation project(':code-scanner')
}
...
}
In the settings.gradle I have added...
include ":code-scanner"
project(':code-scanner').projectDir = new File(settingsDir , "../External/code-scanner")
The project builds fine. But I would like to be able to browse the source, and add breakpoints to the code-scanner project, but it does not show up in Android Studio.
I have tried importing module , but the folder is missing from the subsequent select folder dialog.
How can I add this code to android studio, and set breakpoints and debug....
Just in case. Based on Android Documentation dependencies should be defined outside android block. Maybe Gradle Build figures out your code, but your Android Studio can't find source code of your library.
What version of Android Studio are you using?
1- Make sure you put implementation project(':code-scanner') in app level build.gradle file
2- dependencies block should not be inside android block:
Not like this:
android {
dependencies {
implementation project(':code-scanner')
}
}
But like this:
android {
...
...
}
dependencies {
implementation project(':code-scanner')
}
I don't know which IDE you are using but most IDEs like Android Studio or IntelliJ look like the pictures below.
Or you can view your folder structure in Project view like this:
If you didn't accidentally delete it, it should be there.
The actual problem is the location of the project, which is outside of the root project directory:
include ":code-scanner"
// project(':code-scanner').projectDir = new File(settingsDir , "../External/code-scanner")
Better add it as a library module within the root project, then the code should be within IDE scope.
If you don't want to move the project into there, you could put a built artifact into the libs directory.
Adding a symbolic link might also work out (it's rather a file-system issue than a Gradle issue).
'code-scanner' project you have to add as a library to the current project,for that in code-scanner build.gradle file you have to add
apply plugin: 'com.android.library'
please check if it is missing.
I'm new to android.
I build a new project in android studio, but I can not sync the gradle.
I've searched and there were some recommendations which said the solution is making changes in module/build.gradle
I found two build.gradle but I don't know which one is module/build.gradle, however I did make change to both of them.(I added android method)
the first grdle file
second one
The tab you're looking is Project. It's like a File Explorer.
It says Project change it to Android from drop down menu.
That tab will have only the necessary files. There you will find both the Project gradle and module gradle.
The thing is you can find those files in Project also but it's easy and more convenient to work in Android Tab.
You not necessarily need to make changes to build.gradle in order to run a Gradle sync task. Let me first answer your first question:
I don't know which one is module build.gradle
When you crate a new Android studio project there are two build.gradle files you see. One in MyAppliaction/build.gradle and other is app/build.gradle.
Here MyAppliaction/build.gradle is the Project gradle file which is also called global gradle where you can configure project wide golbal configurations. As per your screenshot you have added depandencies{} in project build.gradle which is not correct(that's why your gradle sync is failed!), you can add depandencies object only in module build.gradle.
app/build.gradle is the "module" gradle file where you can configure module specific configs and dependencies. Module build.gradle will at least one for each module if you create one more library module in your project, that will have separate build.gradle.
but I can not sync the gradle
Yes, when you make any change to project or module build.gradle, you get a "Sync" button on top which can start gradle sync. But if you want gradle sync anytime just open on "Gradle" tab from right and click "sync" icon on top left. (see screenshot below)
Is there a way to reset the default gradle and plugin, without resetting all my settings, so I don't keep having these errors when creating new projects?
Error: Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to
So in the top level build.gradle I update to:
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
}
And then change the gradle to 2.10 as per requirements here.
2.0.0-alpha5 (2016/1/14) // hence alpha6
Needs gradle 2.10 to work
I think you need to follow below step to use Default gradle wrapper(recommended):
Android studio -> Settings -> build tools -> gradle -> Project-level settings -> select Use default gradle wrapper(recommended).
And sync gradle and rebuild your project.
See Below image to get more idea:
It's work for me. I hope its helps you.
Android Studio Template Files located on below path:
{android_studio_installation_path}\plugins\android\lib\templates\
Now for editing every type of Android Studio Template Project you must edit respective file
For Example: (edit android studio new project template)
we must edit below files:
{above_path}\gradle-projects\NewAndroidModule\root\build.gradle.ftl
In this file you must add dependencies that you want to add in every project that you create it, inside the block of dependencies
dependencies {}
Hope my description has been helpful
I'm migrating from Eclipse over to Android Studio and am looking at the Navigation Drawer example from Google. Right away, I see that I get this warning;
It looks like I need to use the v7 library rather than the v4. I can't figure out how to do this. In Eclipse, I just added a dependency from the build tools, but I see no such option in Android Studio. If I look at the build.gradle file, I can see this:
dependencies {
compile 'com.android.support:support-v4:21.0.3'
}
I just downloaded Android Studio yesterday, so I think that I should have this dependency somewhere, but I just don't know how to include it. Can someone tell me how to do this?
From within Android Studio, you can go to File, Project Structure, select your module, and go to the Dependencies tab - you'll see a list of dependencies - you can add new dependencies via the + sign near the bottom of that screen - it will automatically suggest the most popular libraries and all Google libraries including the one you want: appcompat-v7. This controls the build.gradle file and, in your case, adds the line:
compile 'com.android.support:appcompat-v7:21.0.3'
Note that you can also use sites such as Gradle, please to manually figure out what the dependency should be and add it to your build.gradle file yourself if you'd like.
eg.
`dependencies {
compile 'me.grantland:autofittextview:0.2.+'
}`
Where do i add this and how to make it work? i am trying to incorporate autofit textview in android
Find the build.gradle for your project, add the compile statement to the existing lines in the dependencies section. Android Studio will prompt you to "Sync Gradle Project Files", which will trigger everything required to find the library. After the sync you'll be able to import and use the classes as required.
If you want to use this then you need to have an Build-Management Tool like Maven, Ant or Gradle. Then this Tool downloads the dependacys for you.
But if you dont have something like this then just add this file to the project:
http://repo.maven.apache.org/maven2/me/grantland/autofittextview/0.2.0/autofittextview-0.2.0-sources.jar