ReactNative add Gradle Dependency using Android Studio - android

I am very new to Mobile Development especially with the use of Android Studio and Java (but i'm familiar with the language already as i came from C#). But the challenge is i don't yet how to configure the project itself unlike what i can do in VS.
Basically i am trying to include a downloaded SDK, the package looked like it is the same as my project (contains Gradle, etc, etc, so i've thought this is Gradle Project).
What i have tried
is going to file -> Project Structure -> Dependencies -> Add Dependency. Which is basically including a Gradle Project from the options.
It went a-okay but i'm not aware yet it this was right? I checked the Docs from android studio and included the dependency in my Gradle.
It goes like this: implementation project(":MyDownloadedProject")
I know this is pretty simple but i've been checking out stuffs for a long time already but unable to find any useful resource.
Thanks a lot!

Add build dependencies with autolinking or by manually adding to build.gradle
see https://developer.android.com/studio/build/dependencies

Related

Composite Builds in Android Studio

I am looking to use Gradle's new composite build feature in an Android Studio project called MyProject that includes both an Android Archive library (.aar) called DroidLib and a Java library (.jar) called JavaLib. These libraries are currently checked into version control due to my inability to get Gradle to pull dependencies from our internal Artifactory. That is, the DroidLib project has the JavaLib.jar checked into git under the libs folder and the MyProject project has the DroidLib.aar checked into git under its libs folder. I would like to make changes in both DroidLib & JavaLib while debugging and consuming the changes in MyProject w/o manually rebuilding from the dependency projects.
The new Composite build feature in Gradle offers just the thing I need however it looks to be something triggered from the command-line via a flag such like this:
--include-build ../DroidLib
In the Gradle docs it looks like this flag allows Gradle to override a dependency declared in the local project with a similarly the project declared in the included build. This would make sense since they both would use the same group/name/version scheme. I'm having trouble trying to understand how I would use this from Android Studio where my DroidLib dependency is declared as a local filesystem based dependency:
compile(name:'DroidLib-1.19', ext:'aar')
How would the command line flag tell Gradle which dependency is overridden since there is no apparent group/name/version declared on DroidLib? Also how could I make use of this in my app launch run config which uses the Gradle-aware make feature? Is there a way to pass add'l options to the Gradle-aware make or am I over-thinking what has to happen here?
Short answer
It is not available yet (it is in IntelliJ 2016.3).
More details
According to this blog post, the feature is in IntelliJ 2016.3:
With composite builds, everything is much, much simpler. All you have to is to attach the Gradle projects of these libraries via the Add button in the Gradle tool window (my-utils in our case), and then select Compose Build Configuration from the context menu for the original project.
Unfortunately, according to this release note, Android-Studio 2.3 is based on IntelliJ 2016.2. So we'll have to wait for IntelliJ 2016.3 to be merged into Android Studio =/.

Android Studio Gradle Dependency Check

I am trying to develop a Google Play Services like structure which is split into its own separate components (libraries) that can be added to Android Studio as dependencies. For example what is displayed below;
Like the Play Services libraries I would like to force the user to use the same version for all the libraries when adding more than one, as seen below;
I am wondering how the build.gradle file determines this? Is it built into Android Studio, is it coming from the build tools plugin?
As I would like to do something like this, if anyone has any helpful suggestions/links it would much appreciated.
You can use Lint to define custom rules based on your needs.
There is a really good explanation on topic with an example on Android Studio Project Site.
An easy way to start defining your own Lint rules is by modifying the sample project provided at this link http://tools.android.com/tips/lint-custom-rules/customlint.zip?attredirects=0&d=1
This way you will have all the dependencies set up to use the Lint APIs.
Source http://tools.android.com/tips/lint-custom-rules

How can I include an android library into an existing project?

I've been trying to use this solution into my android project:
https://github.com/jlhonora/multistatetogglebutton
I tried since several hours, but I only managed to messed up with everything, forcing me to delete everything, reseting android studio, clone my project and restart from scratch.
I tried the solutions explained in android arsenal but it didn't do the trick.
It's all in the README on the git page you linked.
You need to include the following line within the dependencies block of your build.gradle:
compile 'org.honorato.multistatetogglebutton:multistatetogglebutton:0.2.2'
Then you can use the library, once you have sync'd the build.gradle (which it should immediately ask you to do).

How to use/import a github project into existing android studio project?

I am currently working on an android app. I decided to add some animation effects to it.
When I googled it, I came across this GitHub Project(I am new to GitHub).
I have downloaded the zip file and imported it into android studio using File-> Import Sample.
It created a new android studio project. I am not sure how I should use the new project to get the animation effects in my app.
Should I just copy paste the required modules and edit it to fit my app or is there some other way to do it?
EDIT:
Some websites that I referred say that dependencies should be added. What will the dependency for the given project?
The most libraries provide a gradle (or maven) dependency, you only have to add to your build.gradle e.g.
compile 'com.example.library:library:1.2.3'
For this project I could not find this dependency, so you could try these two approaches: Import the library in Android Studio. I never had to try these approaches, so I am not sure, if the are working.

Duplicate file when deploying apk

This problem seems to come up for a few people, but I haven't been able to apply the solution suggested in other threads for one reason or another so...
I am trying to build a simple android app with an embedded webserver. The server of choice if jetty. I am using maven to manage dependencies with the maven-android-plugin. I have added jetty-server v8.x as a dependency with the default scope. When I try and deploy my apk to the sandbox I get an error
Found duplicate file for APK: about.html
So the file in question is from the jetty package, or rather it is found in two jetty packages, one being a dependency of jetty-server. Other threads out there seem to be suggest I delete the file from one jar or the other but this is not really a scalable solution as I am not the owner of the jars.
Is there a more general solution to this problem? Something that manages the conflict and build or deploy time?
I should note, I am a bit of a Java noob, and have gone the NetBeans and maven route because this is the toolkit I'm familiar with.
OK, found it. The solution is to build using the following command
mvn android:deploy -Dandroid.extractDuplicates=true
There are a couple of issues:
First, to integrate Jetty, your project is going to need a pom.xml file. The Android APK (as-is) does not know how to resolve a pom with Maven dependencies without some sort of bridge. So, you'll need to install a few plugins for Pom management onto Eclipse. Follow the instructions here: http://rgladwell.github.com/m2e-android/
(I found it easier to create a new project using the method described here rather than converting my existing Android app to a Maven project, but I'm sure it'll work either way.)
Second, once you've installed this, you're going to have to make sure your pom.xml contains the necessary dependencies, build goals, and variables. So, open up your pom.xml, and make sure you have the following:
In the "build" node:
sourceDirectory -> src
defaultGoal -> install (I suppose...)
In the "dependencies" node:
... all the jetty/cometd dependencies (org.cometd.java, org.eclipse.jetty, etc.)
Third, you should know that you can't just click the green run button and launch the app via ADB. You have to install it the maven way (Run As -> Maven build/install/test/whatever)
You should open up your war file and check if you actually have two about.html files in there. Some time ago I had two web.xmls in my war files. If you actually have duplicates then you should try to exclude those files.
Maybe you have one file in your project and the duplicate is generated by the maven plugin.
I also just realized that you're probably already properly using the android-maven plugin. One other important tip: change the scope to runtime on the jetty dependencies. This builds successfully for me, whereas using the default scope (compile) always threw the duplicate file in APK error.

Categories

Resources