Adding gradle dependency from git project - android

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.

Related

Adding a repository to my android project as a submodule and keeping my modifications in it in sync with main repo

I've been having issues adding a submodule to my android project. I've tried all tutorials and some solutions available online but none exactly says what to do add a submodule and also keep your commits on it in sync with the main repo.
Solutions I've tried:
Git submodule add repo-link
ISSUE: it adds the submodule to my project but when I click on it to create a new activity in the submodule, it doesn't show an option to create an activity.
TO FIX THIS: I added implementation project(':Tools_Demo_App') in my build.gradle dependancies, then it shows this error.
Then, if I add include ':Tools_Demo_App' to my settings.gradle. This error goes away.
But still, I'm not able to add an activity. It says "Java file outside of source root".
Another solution I tried is to import a module in Project Structure
Assume that before I clone my repo that I wanted to add as a submodule already, and now I'm adding it as a module in my project. It solves that problem of not being able to add an activity. But here, the problem is it doesn't get added as a submodule so all changes I make doesn't get reflected in my main repo.
No matter what I do, so far none of the tutorials available online has helped. Please suggest something, if you've worked with submodules and was able to work with them keeping everything in sync with main repo.
What actually I want to do:
Main Project: A
submodule: demo
I want to keep demo repo as a base app to keep all my designs, libraries and templates so that I can just add this submodule to all my projects and just pick reusable stuff from here instead of rewriting everything everytime.
I figured out the ideal solution to this.
My project name: A
submodule name: x
terminal
git add submodule github-link-to-submodule-x
git submodule update --init --recursive
settings.gradle
include ':app'
rootProject.name = "TutorialKotlin"
include ':Tools_Demo_App'
project(':Tools_Demo_App').projectDir = new File('Tools_Demo_App/app')
build.gradle
implementation project(':Tools_Demo_App')
build.gradle of library module
change
apply plugin: 'com.android.application'
to
apply plugin: 'com.android.library'
remove applicationId
make sure there is no launcher activity in AndroidManifest.xml
sync the project and it works fine.

Can't open ics-openvpn with android studio in mac

I clone OpenVPN project in ics-openvpn. And then I install NDK, CMake, swig(4.0.1), update git ... follow doc/README.txt and I open it with Android studio after that.
But when open the project with Android studio I can't see another package in the project.
Here is my result:
How I can fix it to see all the packages and build the project?
Thank you so much!
if you want to devlope on this project follow this steps:
clone the repo
create a new empty project
click on File then new then import module and go to the repo that you download. open it and choose main folder
build the project
open terminal from the android studio and type cd main/cpp or the name that you name it to this module and download this sub modules :
git submodule add https://github.com/schwabe/openvpn.git
git submodule add
https://github.com/schwabe/platform_external_openssl.git
git submodule add https://github.com/ARMmbed/mbedtls.git
git submodule add https://github.com/schwabe/openvpn3.git
git submodule add https://github.com/lz4/lz4.git
git submodule add https://github.com/chriskohlhoff/asio.git
run this commands on terminal :
git submodule init
git submodule update
go to build.gradle for openvpn module and change the following :
id("com.android.application") to id("com.android.library")
copy this snipt of code that exist in build.gradle for the library and paste it in your build.gradle inside android script :
flavorDimensions("implementation")
productFlavors {
create("ui") {
setDimension("implementation")
buildConfigField("boolean", "openvpn3", "true")
}
create("skeleton") {
setDimension("implementation")
buildConfigField("boolean", "openvpn3", "false")
}
}
add the module in the dependency in your build.gradle :
implementation project(path: ':your-module-name')
sync the project and it is done :-)
NOTE: if you can not see the module files click on the gradle on the right of android studio and left-click on the openvpn module and choose refresh Gradle project.
I hope it can help someone.

Git submodules in existing gradle project

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.

how do you clone a project from github into the same project

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

Library projects in Android Studio only work if nested in the project tree?

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

Categories

Resources