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)
Related
I have a problem when using the aar module dependency aar module as the below issue explains.
https://github.com/dcendents/android-maven-gradle-plugin/issues/65
I have a project such like a client-server structure.
It has 3 modules:
app (my server to provide some service) -- apk module
sdk (my sdk to provide some API to communicate with my app) -- aar module
common (something which should include both in my app module and sdk module ,such as utils,beans,etc. --aar module
I do not want to write it in my both app and sdk modules, debugging and modifying should work twice.
Any idea how I can resolve this?
I'm not sure exactly what you did wrong there, but I've created/modify those gradle scripts and they're working great: https://github.com/sensorberg-dev/gradle-scripts
I can see you're trying to "install" on your local maven. To do that, you have to add this line at the end of the build.gradle from the common module this line:
apply from: 'https://raw.githubusercontent.com/sensorberg-dev/gradle-scripts/master/publish-to-local-maven-repo.gradle'
and then add the metadata to the gradle.properties files, like this:
project gradle.properties:
POM_GROUP_ID=com.company.omg
POM_VERSION=0.0.1
POM_PACKAGING=aar
and common module gradle.properties:
POM_ARTIFACT_ID=common
then it's just call: ./gradlew clean installArchives
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.
I am trying to create android aar which uses play services. I have added playservices dependency in library gradle file. But when aar is exported in release mode runtime it is not working.
How to add google play services in aar?
Please help
You may want to check these steps in adding your library as a dependency:
Add the library to your project in either of the following ways (if you created the library module within the same project, then it's already there and you can skip this step):
Add the compiled AAR (or JAR) file (the library must be already built):
Click File > New > New Module.
Click Import .JAR/.AAR Package then click Next.
Enter the location of the compiled AAR or JAR file then click Finish.
Import the library module to your project (the library source becomes part of your project):
Click File > New > Import Module.
Enter the location of the library module directory then click Finish.
The library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.
Make sure the library is listed at the top of your settings.gradle file, as shown here for a library named "my-library-module":
include ':app', ':my-library-module'
Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:
dependencies {
compile project(":my-library-module")
}
Click Sync Project with Gradle Files.
But, if it's an app module that you want to reuse, you can turn it into a library module by following these steps to convert an app module to a library module:
Open the module-level build.gradle file.
Delete the line for the applicationId. Only an Android app module can define this.
At the top of the file, you should see the following:
apply plugin: 'com.android.application'
Change it to the following:
apply plugin: 'com.android.library'
Save the file and click Tools > Android > Sync Project with Gradle
Files.
For a more detailed information, see this documentation. Also. this related SO post can give additional insights.
As play-services now a days contains aar library instead of jar, we can not merge aar file with library i.e. another aar file. And, hence it is not possible to add play-services inside aar file. Best solution for this problem is who ever is using aar made by you, tell them to add play-services dependency in project.
Add a new module to your project and select import .JAR/.AAR Package.
After you added the module proceed like this : Project Structure → Select the app module → Dependencies tab → clieck the + button → select the module you added → Ok
I'm stuck trying to add https://github.com/ge0rg/MemorizingTrustManager to my Android Studio project (which consists of one MainActivity only at the moment). I tried the steps in the readme and did some Google research but no success. I just can't manage to integrate this package as library. Maybe someone has already succeeded doing so and can help me out.
Whenever I try to add this as library, its add only example module(example is the name of module in the library) but I want to add whole project in studio project.
EDIT
Project Screenshot
Download Demo Screenshot
It seems like you've put a folder of sources in the libs directory. It would be better to included those sources as their own module just as you have done with the emoji library.
Click an existing module
Press F4
Click the Green Plus add-module button in the top left.
Select Import Gradle Project
Select the MemorizingTrustManager sources directory
Double check that Android Studio has added dependencies for you, otherwise look in settings.gradle and add the module name (eg. include :memorizingTrustManager), then in your main module, add the same module to dependencies:
compile project(':memorizingTrustManager')
Finally check the gradle file of the imported MemorizingTrustManager module and ensure it has
apply plugin: 'com.android.library'
instead of
apply plugin: 'com.android.application'
and that it does not contain an applicationId
I've recently started doing Android development again and I am not yet used to the new gradle build system. Any dependency I add (so far I've tried Joda DateTime and butterknife), it always throws an error NoClassDefFoundError.
Here is what I've done. I'm using IntelliJ.
build.gradle:
compile 'joda-time:joda-time:2.1'
compile 'com.jakewharton:butterknife:4.0.1'
File > Project Structure > Modules > MyModule > Dependencies > Add Library, download from Maven, click export and bump it up the list.
My dependency list now includes a maven module com.jakewharton:butterknife:4.0.1
What am I doing wrong here? My IDE resolves everything fine, but at runtime none of the classes can be resolved.
Side note: My BUILD would not even complete until I added the above line to build.gradle. So I have to add the dependencies in Project > Project Structure AND to the build.gradle?
Also my project structure is:
UITest (parent)
UIBeta (android application)
UILib (android module)
I see the butterknife lib in the UITest\libs folder, shouldn't the children be able to find this?
Well I was going to delete this but maybe it will help someone else:
My gradle clean was broken because some aar was locked and it could not delete it, I had to close out IntelliJ, rename the aar (appcompat7 I think it was), then restart. I might not even have had to rename the file as I'm guessing the lock was released upon closing.
After restarting my clean worked, upon next run no more error.