Android studio maven project - jar not working - android

Hello everyone I have added a jar library in my android project. It is a maven project which references another library in its pom.xml. Although the library works fine when tested in eclipse, it does not work in android studio, and gives a class not found exception. The class not found is a class in the library referenced in the pom of the jar library. Any ideas why this is happening? Thanks.

In Eclipse, the other library defined in pom.xml may have been cached already so the library can be accessed from cache. If possible, add the .jar of the other library to you project as well.
But if you use gradle as your build system, it would be best if you can include the repo of the library you need instead of using it's .jar. If it is available in Maven most probably it is available for Gradle as well. You can search your library from the Maven central and find the gradle info at left bottom of the library's page.

Related

Android studio 2.2.2 jitpack dependency url not synced and getting depends on one or more Android Libraries but is a jar

I have extracted .aar library as a library project using eclipse and using as submodule( only one classes jar containing this lib) in Android studio 2.2.2.
Note: currently I am creating a Mini Library Project using the support submodule project.I have synced with submodule to Mini Project and run project and saw output successfully. now, am converting main project as a library. I have removed application plugin and comment launcher in manifest and application id also.( In this MiniProject having two jars in libs folder, one for Ksoap, and another one jar.)
GITHUB PART: then, I uploaded this library project to Github.
Jitpack PART: then, using git, I synced this git code into Jitpack repository and created dependency URL from Jitpack using public url.
Final: finally I have synced this library jitpack url into New Project. It could not synced. getting error like this..
Error:Module 'com.github.vh*******v:MyApp3:-SNAPSHOT' depends on one or more Android Libraries but is a jar.
can anyone help to find the solution

Importing eclipse android project into android studio

I am trying to import an android project created in eclipse into android studio. This main project also refers to another library project in the same eclipse workspace. The folder structure is like this:
workspace\app1
workspace\lib1
When I import the main project into android studio, the library project is automatically imported as a sub-project (or shall we call it a module) within the main project. That's not what I want. The library project is shared by multiple apps I am maintaining. It should sit in parallel with other app projects in terms of folder structure. I wouldn't want it to go understand any particular app project.
Please help explain how I can make the library project stand its own and refer to the library project from other app projects in android project. I am fairly new to the gradle build system. So detailed instructions would be highly appreciated. Thanks a lot!
Since you are importing in android studio, I assume you are moving to gradle build system. In your case , I think, it would be best to have a separate AS project for library. Use that project to generate a jar file and then import that jar using gradle build script in each project you want to use it.
If you are sharing the same library across multiple, you can configure them as separate AS project and have "aar" file as output. (In your gradle you put>> apply plugin: 'android-library'). You then define them as dependency in your gradle file. (either through maven repo or putting it in your libs directory and defining it in your dependencies section). You can find more info at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-projects
You can use version control tool such as git to synchronize the library project in every main project. But you need to use a version control tool to manage all your projects first.
Read here on "AS Modules"
review 57.1.2 on "common behavior"
Take a look at a project built on AS pattern of modules as libs used in eclipse (gradle.settings) pictured
all the includes are modules
maybe you can rethink the idea of how to get AS to work for you in reusing code....

Eclipse -> Android Studio migration: how to include v4 support library (also including the ant build script)

I have a setup of android project on eclipse and I want to migrate to Android Studio. So, I have android-support-v4.jar that I use for my main project and my Facebook lib-project.
I guess I have to exclude lib-projects as a folder in my main module (lets call the main module Jack). Jack has dependancy on the facebook lib-project.
How should I define the android-support-v4.jar as a separate library and use it in both projects? Or should I just use directly the jar files and leave them in both Jack's libs folder and Facebook libs folder?
If the first option should be done, will ant clean release still work (with the build.xml android generated file)?
In Android Studio, builds are done with Gradle now. Gradle is different. With gradle, you tell your project which jar's you need, and it will connect to a server and download them if it doesn't already have them when you compile your apk.
A few things to note:
When you install Android Studio, it has it's own Android sdk directory. You have to download everything from the sdk downloader (from inside the Android Studio App) again. Don't bother trying to switch the sdk download path to your current one. You will only encounter bugs (Or at least I did).
So your question is worded very confusingly. It sounds like you have a main module, and then you have a library module, and the library module uses the support library.
You'll need to set it up so the main module has a dependency on your library module. From there, you'll need to go into your library module's gradle file and tell it that you want to include the android support library
dependencies {
compile 'com.android.support:appcompat-v7:19.0.0'
}
The support library is a little weird in gradle. Gradle normally would download the dependencies you need. However, android studio requires that you have the support library installed through their sdk downloader (top-right group of icons in android studio. The download icon).
After you get all your dependencies entered into your gradle file, you'll then need to go to Tools -> Android -> Sync gradle files with project. From there compile errors should go away, and you should be able to run the project.
Best of luck. By the way, Here is the documentation on Gradle on the android website. I find myself having to go to it A LOT, especially when I made the switch from Eclipse to Android Studio. This + Various tutorials I found as needed via google. http://tools.android.com/tech-docs/new-build-system/user-guide
EDIT: This link might also be helpful. Google has some steps for switching from eclipse to Android Studio: http://developer.android.com/sdk/installing/migrate.html That with some of the stuff above may prove helpful.
While I haven't tried this myself, I suggest you use the recommended migration steps provided by Google in this article.
Before you do that, though, make sure that you either:
Check that both support libraries on the main project and dependencies have the same version (Eclipse will complain about it during build time, and will likely cause problems during conversion to Gradle script.); OR,
Uncheck the "Android Private Libraries" entry on the Order and Export tab of the dependency project's build settings.
If the migration process described doesn't work smoothly for you, you can always call the Ant build script from within the Gradle script, as described here.
The Android Studio uses only Gradle, but you can export Android ant project from eclipse.
To do that go to File -> import project usually next, next, next... works.
If not go to project setting Shift + Ctrl + Alt + S and under modules -> PROJECT_NAME -> Dependencies you can add your support library.
To add a Facebook library you must add it as another module to your project.
If you still want to use Ant there is another option: Use Intellij IDEA which support Ant.

ViewPagerIndicator Dependencies Missing

Using: Eclipse & ADT20
I am having issues using Jake Wharton's ViewPagerIndicator in a new project.
After following the instructions on Jake's github page I receive an error in my application when adding the library. If I look in the Android Dependencies (located; Properties > Java Build Path > Libraries) there is a library.jar referenced but it has a red cross and says "missing".
On github page it says "A standalone JAR is not possible due to the theming capabilities offered by the indicator widgets." so why is my project trying to reference one?
I have tried removing the Android Dependencies and cleaned the project with to no avail. I've ran "Add Library Support" and "Fix Project Properties"
Any help would be much appreciated.
EDIT:
The solution can be found here: Using Jake Wharton's ViewPageIndicator
I had the same issue
I removed my project from Eclipse and copied it beside library project
then add my project and library project to Eclipse again and in project.properties file of project replaced this
target=android-7
android.library.reference.1=../library
also changed target SDK of library to 7
really strange but worked
I created a new Android Library Project, copied over the files from ViewPagerIndicator's "library" subdirectory and then (to fix some problems with some Holo themes not being found) edited the project.properties to:
target=android-14
This last bit at least meant the library project would compile. I have no idea why it is initially set to level 4.
https://github.com/JakeWharton/Android-ViewPagerIndicator/blob/master/library/project.properties

How do I build my project with ANT when it depends on a non-library project with an Android library project dependency?

I'm trying to build my project using ANT. My project uses ActionbarSherlock, and Roboguice-Sherlock. ActionbarSherlock is an Android library project, but Roboguice-Sherlock is not. It's not even an Android project at all. See here:
https://github.com/rtyley/roboguice-sherlock
I can get ActionbarSherlock to build using ANT no problem, the problem lies with Roboguice-Sherlock. It's not an Android project, yet it has dependencies on Android and ActionbarSherlock, as well as Roboguice. When I try to build I get a ton of errors saying it can't find the Roboguice-Sherlock stuff.
If your project has the Roboguice .jar and the library project reference to ActionBarSherlock already configured you should be able to just drop it into your libs/ folder to have it automatically picked up.
I am working with Roberto to ensure that the .jar of his project gets uploaded to GitHub for non-Maven users to use.
For now, you can clone the project simply run mvn clean package to get a standalone .jar in the target/ folder which will enable you to do as I described above.
You need to add robiguice-sherlock as a .jar to your Android project. You can download it here (click Download (JAR)). Trying to build the source in Android will fail because it is not an Android project. Once it is in your directory, you need to open project properties and add the .jar to your build path.

Categories

Resources