I have some application which has few modules that i want to to replace in submodule.
Can I do that in the current project. Create new repo with these modules.
Yes you can achieve this in following way :
Say your main project is in X_REPO\Project\app
Move your module in a separate repo say Y_REPO
Then add Y REPO as submodule in X_REPO\Module1
Now make the following changes in
settings.gradle
include ':Module1'
project(':Module1').projectDir=new File('../Module1/module_directory')
X_REPO\Project\app\build.gradle
compile project(':Module1')
Since Android Studio uses same gradle build system, same can be achieved in Android Project as well.
Related
I have a similar problem as described in this
Question
So I have an android project which depends on this popular library XChange. As XChange is not very android friendly (Uses JDK 8 streams etc and Android does not support them fully (Link) and I have some other custom requirements for the library, then I decided to fork the project.
So currently I am using IntteliJ Idea to develop the XChange maven project, commit the changes and use Jitpack.io to include the new commit as dependency to Android studio. This works, but is horribly time consuming.
So I have tried or though of the following ways to overcome this.
1) Convert the Maven project to gradle and use the Android studio import feature - This makes a copy of the source code and therefore the git support drops and I cannot pull the changes from the main origin of XChange
2) Convert to gradle project and try to include it through settings.gradle and include it as dependancy as in the referenced question accepted answer at the beginning. This does not work unfortunately, because as XChange has a lot of subprojects and the subproject dependancy import fails.
include ':xchange-core'
include ':xchange-kraken'
project(':xchange-core').projectDir = new File(settingsDir, '../XChange/xchange-core')
project(':xchange-kraken').projectDir = new File(settingsDir, '../XChange/xchange-kraken')
3) Use MavenLocal somehow, but I have no idea how to get this to work (Using IntelliJ idea)
XChange has the following setup
\XChange (has its own pom.xml with settings for all subprojects)
+ xchange-core (main dependency for all subprojects)
+ xchange-kraken
+ xchange-binance
+ ...
So to sum up, Does anyone has a way to save some time on building the project when I need to include my own fork of dependency from disk to Android Studio?
EDIT
Example problem
Settings.gradle
include ':app'
include ':xchange-core'
project(':xchange-core').projectDir = new File(settingsDir, "../XChange/xchange-core/")
Build.gradle
...
compile project(':xchange-core')
Error
Error:(4, 0) Could not find method compile() for arguments [{group=com.github.mmazi, name=rescu, version=2.0.1}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Here is how I resolved my problems.
Step 1. clone project (in my case the XChange fork) as git submodule to you main app folder, so you can keep version control
git submodule add 'YOUR_GIT_REPOSITORY'
Step 1.5. If you had a maven library project, then run gradle init from terminal at your library folder. This will convert your maven project to gradle one. Necessary for Android Studio.
Step 2. If you have any top level build.gradle or settings.gradle, then forget about those. Defenitely not a perfect solution, but the only way I got it working. In you main apps settings.gradle, you must define each submodule like this
include ':app'
include ':xchange-core'
...
project(':xchange-core').projectDir = new File(settingsDir, "../XChange/xchange-core/")
...
If you had a top level build.gradle in your library project, then put anything you can in your apps top build.gradle file and everything else I copied to the library submodule build.gradle files (Yes, to each and every one)
Step 3. In your apps build.gradle files, now you can include you library submodules as
...
implementation project(':xchange-core')
...
Also, this Medium post was very useful Link
If I have project-A which is a SDK and its being exported as a AAR into project-B which imports the module as a AAR how could i go about linking the two modules so changes made to the AAR in project-B don't have to be duplicated in the original project-A?
Create a Project A (library), create project B(application) and put them in the same project.
update the settings.gradle file like this:
include ':projecta', ':projectb'
And make sure the projects are in the same directory
.gradle
.idea
projecta
projectb
etc
By doing this you won't have to explicitly add the aar to project B because they will be in the same project and both automatically be built when you make a release.
Edit about linking with multiple projects
In the case you want to have links to multiple projects your best bet is to create a maven repository.
Doing so will allow you to use your project in the following way:
build.gradle
dependencies{
implementation com.mydomain.projecta:1.0.1
}
Any project you want to use you project A with can be used by writing the line above.
When you update project A you update your maven server and change the version to 1.0.2
You also will have to update the dependencies in the linked projects:
dependencies{
implementation com.mydomain.projecta:1.0.2
}
I think that is the most stress free way to distribute your SDK in one place and easily resuse it in multiple places.
Here are some links about setting up a maven server
https://inthecheesefactory.com/blog/how-to-setup-private-maven-repository/en
https://www.androidauthority.com/add-a-github-library-to-android-studio-using-maven-jcenter-jitpack-777050/
In android studio how do you git clone a project from github into the same project?
If I got your question correctly, you want to check out some library and add it as a dependency to your (gradle based?) project.
The prefered way would be to checkout it separately and built it as a library project. And if you have maven you can then install it to your local repository.
The other way (and probably what are you trying to achieve) is to add it as a submodule of your local repository.
git submodule add git://repourl.git yourSubmoduleFolder
Then you can add this library as a module dependency to your application module. (You don't have to use git submodules, you can always just get the repo as a zip and extract it into your project)
If you put your library under libraries folder in your project then you can do it like this.
Add this to your settings.gradle
include ':libraries:yourLibraryModuleName'
Add this to your build.gradle
dependencies {
compile project(':libraries:yourLibraryModuleName')
}
You should now be able to build your application with the submodule
Please note that this was just a quick answer, you can find more info on both gradle submodules and gradle module dependencies here on StackOverflow. I guess this should be enough to point you in a right direction.
It does not. However it's a good practice to put it in libraries or libs,...folder
I am trying to add this project to my gradle project in Android studio. I tried using Gradle git plugin as described here but Gradle says it can not find those files even though i placed folders inside app folder in my project. I added in dependencies in gradle.build file to include project in build but no luck, it just says project does not exist. Does anyone know good tutorial or have any suggestion about this?
You could register the repository as a submodule like this
$ git submodule add my_sub_project_git_url my-sub-project
Then include the project in your settings.gradle file which should look like this
include ':my-app', ':my-sub-project'
Finally, compile the project as a dependency in your application build.gradle file like this
dependencies {
compile project(':my-sub-project')
}
Then, when cloning your project, you will only have to add the option --recursive to make git automatically clone the root repository, and all its submodules.
git clone --recursive my_sub_project_git_url
I hope it helps.
I'm trying to build a project dependent on ActionbarSherlock in Android Studio.
After much reading I've ended up having a working build, but only if I nest the ABS project inside my main project like so:
MainProject
MainProject\ABS (copied here and then used import module)
MainProject\MainModule (the one created by the wizard)
I had to edit the various Gradle files, settings.gradle is as follows:
include ':OnTop'
include ':ActionbarSherlock'
I fixed the dependencies in the build.gradle files accordingly.
This is suboptimal, I think. Surely I don't want to replicate the ABS module in every new project that uses it? What should I be doing instead?
Every step are here : How do I add a library project to Android Studio?
If you want to more about gradle see the Google I/O conference by Xavier Ducrohet on youtube : http://www.youtube.com/watch?v=LCJAgPkpmR0
I searched this issue enough and finally these are my results:-
This sample project
-> project root
d:\asprojects\thisproject
-> module
d:\asprojects\thisproject\MyModule
-> libraries
d:\asprojects\lvl
d:\asprojects\MyLibrary
-> jars
D:/asprojects/android-support-v4.jar
D:/asprojects/GoogleAdMobAdsSdk-6.4.1.jar
-If you want to use external (outside the project) libraries then the settings.gradle has to point to it like so:-
settings.gradle
include ':lvl', ':MyLibrary', ':MyModule'
project(':MyLibrary').projectDir = new File('D:/asprojects/MyLibrary')
project(':lvl').projectDir = new File('D:/asprojects/lvl')
-Then you need to setup the build.gradle for the MyModule correctly like so:-
build.gradle
dependencies
{
compile files('D:/asprojects/android-support-v4.jar')
compile files('D:/asprojects/GoogleAdMobAdsSdk-6.4.1.jar')
compile project(':lvl') compile project(':MyLibrary')
}
-But the IDE will not like these absolute paths and will say not found.
-But gradlw from commandline work justs fine:-
gradlew clean
gradlew build
gradlew installRelease
etc