I am developing android library project.I don't want share my source code.I want to create something like jar file.But i can't create jar file as it includes xml layouts.so is there any way to build project without including source code?
I can give you an example of such library. Open Android SDK manager and download Google play services library.
This library contains 'libs' folder with google-play-services.jar which contains all the source code. Also there is 'res' folder and android manifest file to be able to add this library to every android project.
First thing is to have the full library-project ( example : FullProject).
Then I import the full library project (FullProject) in a new workspace and check “Copy Projects into workspace”. This new project must have the same name ( FullProject)
in the copy, i removed the source code.
in the app-project i added the source-less-library-project as android library
in the app-project i added the .jar file with all the binary classes from the full library-project ( right clic on directory “source” of the full library-project, export as jar and check « Add directory entry » ).
in the build path of the app project, in "order and export", check the .jar exported
update the manifest file of the app project with all views of the library project .
clean the app project
It’s all !
Related
I had downloaded the Android Studio 4.0.1 and the same version for OpenCV Library.
I made a random Java project just to set the library, but when I select the library (the path is correct -"C:\opencv-4.0.1-android-sdk\OpenCV-android-sdk\sdk\java") they don't show it and let me finish this action (please see the image below).
Why I can't select the library? I am watching an Youtube video for this (beginner here) and the guy can see it totally different.
You don't need to select library. Add this module then do this steps:
Open Project Structure-> Dependencies-> app -> Add module dependency-> select opencv module.
You can access opencv classes right now.
For me the import project functionality also doesn't work, but what worked is to create a new empty project, clears its artifacts, and copy the OpenCV library artifacts from OpenCV-android-sdk\sdk\java\ folder. There are 6 steps:
copy AndroidManifest.xml to src/main
copy sources to src/main/java
copy res folder to src/main
copy libs folder from OpenCV-android-sdk\sdk\native\libs to src/main and rename it to jniLibs
create folder src\main\aidl and move file src\main\java\org\opencv\engine\OpenCVEngineInterface.aidl to folder src\main\aidl\org\opencv\engine\
in build.gradle set project as library by specifying plugins { id 'com.android.library'}
You can refer to the image in order to see the final project tree:
project structure image
i have found this sdk: is24-restapi-java
and i want to import it into my android studio project for further use.
But i can't find a way to include it.
I did some searching through the github project i cannot find a simple jar or dependency that i can include into my project and all advances to generate a jar or something failed.
Can anyone give me a guid or something to include this sdk into my project or am i using the wrong approach?
Goto File -> New -> Import Module.
Source Directory -> Browse the project path
Specify the Module Name – it is used for internal project reference.
Let Android Studio build the project.
Open build.gradle (Module:app) file.
Add the following line with your module name in place of “projectName” in the dependencies block:
compile project(':projectName')
After this Android Studio would start saying “gradle files have changed since last project sync”, press the “sync now” link to start a sync.
People say they are the same but they are used in different situations as said in developer site
1-Adding libraries without resources
To add a Support Library without resources to your application project:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a libs/ directory in the root of your application project.
Copy the JAR file from your Android SDK installation directory (e.g., <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.
2-Adding libraries with resources
To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a library project and ensure the required JAR files are included in the project's build path:
Select File > Import.
Select Existing Android Code Into Workspace and click Next.
Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
Right-click the library project folder and select Build Path > Configure Build Path.
In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
Uncheck Android Dependencies.
Click OK to complete the changes.
You now have a library project for your selected Support Library that you can use with one or more application projects.
when should I use appcompat_v7 (which is generated with the project automatically )
and when to use android-support-v7-appcompat ?
In which case the programmer needs to add library with the resources in the project ?
please feed me with your experience
android-support-v7-appcompat.jar is a JAR file, containing only compiled Java classes. appcompat_v7 is a Library Project, which contains the previous JAR file, no actual source code, and a great many resources (layouts, images, &c).
In the particular case of appcompat-v7, you need to use the Library Project, since it contains necessary UI resources.
Other libraries (such as v7 MediaRouter or v7 Palette) do not contain these resources, and therefore the JAR file can be used directly.
Note that the difference applies mainly to Eclipse (in which libraries with resources must be imported as a project while the others can be just placed in the libs folder). With Android Studio/gradle this is all handled by the build system and therefore the procedure is the same for both. This is well explained in the Support Library Setup documentation.
The generated appcompat_v7 contains the android-support-v7-appcompat library, along with some resources. If you let Eclipse generate your themes and layouts, they will refer to the resources in the appcompat_v7 project and your project won't build without it. I've never encountered a situation where I needed only the library without the resources, but perhaps you might if you wanted to incorporate a new support library feature into an existing project.
Is there a way, how to add custom library to android app. If I add non-android library to my project it throws error "Only Android project can be add as dependency" and if I reference Android Library to Java Application it throws "This project cannot be added because it does not produce a JAR file using an Ant script." the point is, that I want to keep code on one place (library) and reuse it.
Your best bet is :
1.Create a folder called libs in your project's root folder
2.Copy your JAR files to the libs folder
3.Now right click on the Jar file and then select Build Path > Add to Build Path, which will create a folder called 'Referenced Libraries' within your project
In my project, I need to use external library. That library consists of .class files. I have added folder with this library to my project using properties -> Java Build Path -> Libraries -> Add class folder. I can compile project without any problem, but when I run it, I get failed resolving xy and debugger stops on line where I create instance of class from imported files.
I guess the external library I use isnt linked to my .apk file. How can I fix this? I have tried to check this library on "Order and Export" tab assuming that, it will export the library with my application. But it didnt work.
How can I link this library to my project .apk? Do I need to somehow install this library on device first? Do I need to copy this library in application folder?
PS: I'm using Eclipse Juno, android SDK target 10.
Thank you
UPDATE
I have this library copied in libs folder. External library path is:
my_project/libs/sk/aicit/leg/libraries*.class
I have added ./libs folder in Libraries settings of project.
I do not have .jar version of this library, only .class files.
I have also souce code of this library, but I didnt want to include its classes in my project, it has its own dependencies, I wanted to just "link" it like library. Its an external library I havent written.
UPDATE 2
I have copied all the source files from library to my projects "src/" dir. I have removed Library from Java build path. I can stil compile my project, but when I run it Iget
FATAL EXCEPTION:main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{
com.example/myvideorecord/com.example.myvideorecord.Robot}: java.langNullPointerException
...
What can I do, how to debug this error? :(
steps
Copy the library file into libs folder
select jar file -> right click -> Build Path -> Add to Build Path
clean the project Project-> Clean -> select your project -> ok
Android Studio
For importing a Android library into Android Studio, use the following steps:
1) (Optional) I like having my main Android project contain everything it needs to compile correctly, so I move external libraries into the libs/ directory. Generally, you only need to keep the following directories:
res
src
AndroidManifest.xml
*.iml (This will typically be the name of the library you're importing.)
2) Go to your Project Properties.
3) Go to Modules.
4) Import a New Module (Command + N and then Import Module).
5) Navigate to the library directory you want to import.
6) Create module from existing sources.
7) Click Next three times to add the necessary files.
8) Click Finish to complete the module additional.
9) Click on your project in the module list and go to the Dependencies tab.
10) Click the + button at the bottom and click Module Dependency....
11) Make sure your library you're importing is selected and click OK.
12) Click OK in the Project Properties window.
And you should be good to go.
Copy that library file into libs folder
if u have the source code of the library you can import it in eclipse .
Right click on your project -> properties->android -> reference-> add
and add the library project which u have imported. This will include only .class files of the library in ur project