I want to be able to use the Open Source AOSP Material Design Calculator into my own app where the calculator is one of various other features on my app. I found the code here. My question is the following:
Is it possible to add this open source calculator to my app by simply installing it as an additional package in my app codebase? If so I would like to request some basic overall steps on how to do so. Should I just import it in my project as another package? What do you foresee being some of the steps on how to achieve this (Android Studio specifics).
As the calculator is consider to be AOSP and open source, would it be ok for me to add this package my my codebase? If so what are some of the notifications I as a developer must put on the app to inform users that I'm using an open source project as part of my app. I'm assuming this is required.
In the end my app will have many features where the AOSP Calculator will be one of them. This calculator will be reached via an intent and the user should see the calculator with the same functionality except it will be visually redesigned. The whole point of open source projects is so that developers don't have to reinvent the wheel every time, with that in mind I look forward to any feedback you may have about these questions.
I was having a similar issue in the past. The following steps will ensure that you can integrate this app as a library in your project.
1) Clone the project in your local machine (git clone ...)
2) The project is build using Gradle. Before you do anything go to the build.gradle file and create this task at the end of the file:
task copyDeps(type: Copy) {
from configurations.runtime
into "${buildDir}/libs"
}
3) Now fire up a terminal and navigate to the root of the Calculator project. Type gradle --refresh-depencencies in order for gradle to fetch a couple of jars needed by the Calculator project. When this finishes, type gradle copyDeps in order to copy the dependencies to the project's libs folder (if the folder does not exist create it).
4) Now that the project is ready open your IDE (mine is Eclipse but the steps are pretty much the same). Import the project and then mark it as a library to your project
5) Now upon deployment the Calculator will be packaged with your application and you will be able to fire Intents and open it (check the calculator's manifest file.
As for the Calculator project, yes you have to include somewhere a simple notification. For more check here.
Related
This question already has answers here:
How to make a .jar out from an Android Studio project
(11 answers)
Closed 5 years ago.
I want to create some library that i will use in the future beside my current project.
I can't find a way to create library in android studio.
How to do it on android ?
A library module is useful in the following situations:
When you're building multiple apps that use some of the same components, such as activities, services, or UI layouts.
When you're building an app that exists in multiple APK variations, such as a free and paid version and you need the same core components in both.
In either case, simply move the files you want to reuse into a library module then add the library as a dependency for each app module.
To create a new library module in your project, proceed as follows:
Click File > New > New Module.
In the Create New Module window that appears, click Android Library, then click Next.
There's also an option to create a Java Library, which builds a traditional JAR file.
Give your library a name and select a minimum SDK version for the code in the library, then click Finish.
Once the Gradle project sync completes, the library module appears in the Project panel on the left.
If you don't see the new module folder, make sure it's displaying the Android view.
Visit https://developer.android.com/studio/projects/android-library.html
As introduction I would suggest you to peek into this conceptually simple tutorial. Basically you can start your own library module when you chose your project, without adding any Activity. Then you create your Java Class, usually with a View. When your library is ready, with all its business logic, you can glue everything inserting in the top level build gradle the instruction you are using a library, basically before you remove the following line, that is not needed for a library:
applicationId
(This line in your gradle file is a unique application ID that looks like a Java package name, that identifies your app to the device you are running and in google play)
and then you change this line:
apply plugin: 'com.android.application'
to:
apply plugin: 'com.android.name_library'
When you have a more structured project you can follow the official documentation
As it is well explained the difference between a normal Application and a Library is:
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest. However, instead of compiling into an APK that runs on a device, an Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module.
I would not encourage you to use solutions like web services that do it on your behalf, namely just copying/pasting your existing code. In fact a library often needs specific architectural choices, so is important to consider and learn different factors, is not just writing some business logic is quite complex to explain, but you can imagine that also the choice of what the user can see and modify can be crucial. Also should be as much as possible bug free, because once it is adopted could cause problems to the users. I remand you to a famous post, superbly written where you can find some solution to this aspect.
you can use https://jitpack.io/ is very easy publish an android library. just upload your code to github/bitbucket and paste the repository link on jitpack website. that's all
I am using Android Studio for developing Android apps. But I have heard in Android Studio it is better to have only one app in a single (one project per app) if that is right, then it will be very wasteful to open many frames for many projects. But when I searched I found that
Android Studio project = Eclipse workspace
Android Studio module = Eclipse project
Now, if this is true, it means that Android Studio also can support a multi-app project. If yes, then, is every app in Android Studio independent like in Eclipse (i.e. they do not disturb each other by sharing any file or setting)? Or can we have many apps in a single project? If we can then is there any point to take care of?
Thanks!
Yes, you have two options:
Option 1: Create an addition app module
First create your standard Phone & Tablet Android project, including the auto-generated app module.
Add a new app module: File > New > New Module ... > Phone & Tablet Module
Complete the wizard and name your Application app2 for instance.
Now you'll have both app and app2 in the same project.
To actually run app2 you first need to select it in the pull-down menu in the top toolbar of Android Studio, next to the Start and Debug icons. You can also do this though Run Configurations: Run > Run... > Edit Configurations... and modifying Module.
Option 2: Create an addition library module
This is ideal for creating a separate library that is isolated from the app, and can be shared across more apps (or other projects):
Add a new library module: File > New > New Module ... > Java Library.
Complete the wizard and give your library a good name, like libgoodstuff.
Now libgoodstuff and app will reside in the same project.
To make app sources depend on libgoodstuff, you first have to add the library module to the project settings.gradle to look something like this:
include ':app', ':libgoodstuff'
Then in app/build.gradle you have to depend on the library module like this:
apply plugin: 'com.android.application'
···
dependencies {
···
implementation project(path: ':libgoodstuff')
···
}
···
Yes you can. Inside your project if you want to create a new app do the following:
Create a new module by right clicking on your project -> new -> module
Select phone and tablet module
Now you will be able to run either app. This is an excellent way to share code between two apps as it allows you to keep and develop your libraries in one location.
You can definitely have multiple app modules in the same Android Studio project. Having said that, I've yet to find a reason to define multiple app modules in a project.
If you need different version of the same app, Gradle's build variant is powerful enough to satisfy perhaps 99% of the use-cases (I have a project with a dozen variants, each with its own custom code/res).
If you are writing different apps then it's better to make each its own project so apps don't inadvertently change each other's behaviour.
Not sure what you mean by "is every app in Android Studio independent as Eclipse", but each module is its own world by default unless dependencies to other modules are explicitly defined.
Adding this as an answer since I don't have enough reputation for comments yet.
For the answer to your question - Check this question that I have raised. Is this the same boat you were in ?
TL;DR
I was able to have multiple apps in the same Android Studio Project, build and run them without any issues. Another member
corroborated my claims in the comments on the Question.
#Android Studio Pros : Please check the above link and add your insights. This seems to be a confusing aspect.
My Take
I think I agree with #Kai's answer. But there are instances where we want multiple apps to have common library dependencies and don't want to duplicate the library dependencies. Wouldn't multiple apps be fine as long as the common library dependencies have ONLY common code and nothing else. The separate modules hold the individual app related code and that's where the differentiation is.
Yes, it is possible. As the existing answers showed, it’s quite straightforward to create additional application module in the same Android Studio project.
So I’ll try to answer underlying question why anyone might need it.
It’s certainly not worth it to put multiple completely independent apps in one project.
However, if you app is big enough, you might benefit from putting separate features into separate modules. You can also create a separate executable app module for each feature, so that you can:
launch/debug each feature separately
save some time on every compilation/dexing/putting everything into a single apk
encourage teams/developers to work independently, and even in separate repositories.
The main app module can be used only to combine existing features together.
I’ve recently created an article demonstrating this approach where I tried to explain everything in more details: https://medium.com/#domplebump/multiple-application-modules-in-one-android-project-36e86ceb8a9
I am working on a Android app in which I would like to add plug and play module functionality ,Say I have Two android project
[A] An app for capturing a image using camera and storing it in memory
[B]Enabling map and locate current location .
now I want to add add this functionality in my Another Android app.While going through android developer link and Android Library Projects - Tutorial I figure out that to use plug and play module I have to make my above project as library project so that I can use it in my new app ,now my questions are
1 Is this only way to use library project to add plug and play module
functionally in my app or there are another way also?
2 what are the pros and cons of using library project in order to add
plug and play module functionally?
basically I am researching on how to add plug and play service in my android app and trying to find best solution ,so any clarity on this topic will be extremaly helpful !!!
thanks in advance !!!
An alternative would be to use a linked source folder. In Eclipse, you can set this up in the project settings in the Java Build Path section. You can choose some source code directory outside your project that will virtually be in your project's space (and other projects that use it will do the same). I find this to be handy just from an IDE UI standpoint when I'm co-developing a module along with an app or two. What I don't like about library projects is that they sometimes don't update correctly within your project so you have to rebuild it and your project or clean your project to continue. Also, the module is simpler because it's just a directory of source code files, not an entire Eclipse project.
One other downside of libraries is that they can introduce conflicts that can be a headache to fight. For example, your library might have a different version of the Android compatibility library in it than your main project, and therefore give you compile time errors. Or there are sometimes errors with duplicate libraries, and you have to go fool with the Order and Export settings of your project.
If your module is going to rely on String, layout, and image resources, etc. that are common to all apps that implement the module, then a library project will be easier to work with so you don't have to pass all your resources in through your module's class constructors and duplicate them in each project.
A third option is Gradle, although as far as I know, that would essentially just help automate one of the above two options. I'm not very familiar with Gradle.
I have seen this question, and have some more doubts regarding creating a jar file which I can distribute and can be used in any android applications.
What my requirement is
As I said, I want to build and distribute a closed source library. I
don't want the source code to be visible.
In that library I don't want to use any assets, layouts, resources
etc. But I want to use some android specific codes, like getting
android device id.
The most popular answer in the above linked SO question tells to create a regular java project and import android.jar in it. I tried to do that, but I don't know how to add android.jar to any java project. I would like to get some clarification on that too.
Moreover I would like to know if there are any other methods using android sdk itself (without using java project) create a closed source library jar file.
I think what I want is possible, since google analytics for android native apps seems to have done it. I am sure in the .jar file they distribute they are using android specific codes, since there seems no other way for them to get the device information to display in the analytics viewer.
EDIT : CAN SOMEONE CLARIFY THIS??
I think I have made some progress. This is what I have done
Created a regular android project (not library project, the "is
Library" checkmark is unchecked)
In the project I have coded out my logic. It uses some android
specific classes like SharedPreference, UUID, PackageManager. But
nothing related with assets, layouts also no class extending
Activity. Just a java class extending java.lang.object
Exported the project using Project->rightclick->export->Java->JAR
file. In the next screen I unchecked the checkbox near
AndroidManifest.xml. Set a destination directory to export and
clicked next thrice with keeping the default settings. Then I clicked
Finish, and got a lovely libMyLibraryName.jar at my desktop.
Then I created another android project, added this libMyLibraryName.jar to new project using project->rightclick->properties->java build path -> libraries->add external jar.
And I tried to use my class in the library, in my new project
MyLibraryClass objClass = new MyLibraryClass(this);
And I was able to compile and run successfully. I even sent the library to one of my co worker who was able to use the library in his on machine (Just making sure library project in my workspace wont influence the project using it).
Now I have 2 questions.
1) My first question is , what they meant by the term "true library" in the below given documentation ? Is it any non android java project which can be exported to a JAR file?
However, a library project differs from an standard Android
application project in that you cannot compile it directly to its own
.apk and run it on an Android device. Similarly, you cannot export
the library project to a self-contained JAR file, as you would do
for a true library. Instead, you must compile the library indirectly,
by referencing the library in the dependent application and building
that application.
Well this portion is taken from documentation under title "Library Projects".
2) My second question is, anything wrong with the way I have created the JAR file? Any possible pitfalls which might bite me back later? I would like to make sure I am not doing something terribly wrong, before using it in my important projects.
I might add that I didn't try the method of creating a JAVA project and importing android.jar. I am ready to try that one, if what I have done currently is wrong.
The android.jar will be located where you installed your Android SDK. Under the platforms directory there should be a number of other directories named android-<version>. The android.jar will be there. Choose the one specific to the minimum android version you are targeting.
Once you have that, copy it into your project. If you're using eclipse I think you can just cut and paste jars straight into your project, right click and add it to build path. If you're not using eclipse or any other IDE, you just need to ensure that the android.jar is on the classpath when building your jar file.
After that your newly built android library can be dropped into any Android project.
In answer to your additional questions:
What they mean by a true library is a jar file as opposed to an Android library project.
I don't think there's anything wrong with the way you created the jar file. I would have made it using the android.jar as I mentioned above but your way should also work. To verify this I would examine the jar contents and make sure all you have in there is .class files.
As far as I understand, all the built-in standard apps like (email, music, calendar etc) are built using the same API. So I should be able to import a project like mail / music etc without checking out the full source repository of android. I'v been trying that but I am getting compilation problems like class resolve failure.
Am I doing it wrong? Do I have to get the full android source project to import a project like Mail ?
These apps are open source (mail, music and calendar). But they depend on internal classes and resources and can't be compiled with the SDK
You could pull a Git clone of some particular app. For example - the EMail app from
https://android.googlesource.com/platform/packages/apps/Email/
The first problem is that Google are using MK files for building inside their android projects and Eclipse do not use them. But you can compile it because you have the sources, the XML resources and the manifest also.
The second problem is to deal with the dependencies. For example the gallery app may depend on few camera classes. You can manually copy them to your project.
Other way is:
Using Eclipse for writing code and testing if it builds correctly and using GNU Make 3.82 from http://www.gnu.org tool that will build the supplied Android.MK file and run the app.