I have my Android Studio project structured as follow:
/mysdk
-manifests
-java
-com.xxx.sdk
-ext-libs
-com.yyy.lib (not .jar but .java files instead)
-res
/app
-manifests
-java
-res
I can include com.yyy.lib.* inisde com.xxx.sdk and reference all the methods without any symbol resolution problem in Eclipse project.
But after I transfer my IDE from Eclipse to Android Studio and it tells me it cannot resolve the symbols/methods from com.yyy.lib inside com.xx.sdk (ex: com.xxx.sdk.Activty.java)
How can I fix this dependency problem in Android studio?
If you have no strong preference for the location of com.yyy.lib, just moving it into the parent (is it src/main/java? based on gradle convention) it will probably get picked up.
It appears the IDE is treating src/main/java (or whatever) as a source folder and your package paths aren't matching up with your directory structure
ext-libs.com.yyy.lib instead of com.yyy.lib
That's because Android Studio uses Gradle as its dependency manager, whereas Eclipse uses either Maven or Ant.
You can read more about managing dependencies with Gradle, here.
This answer explains how to add a dependency/library to Gradle in Android Studio.
In your project file browser:
Go to libs folder. and add your library if not present
and then in gradle: add compile files('libs/your_library') in dependencies and then Sync Gradle
Related
How can i use an external, Ecliplse non-android-library-project in my project, without moving or copying or changing it? It is important that that library remains untouched because it is still being edited by others and other projects are referenced to it there aswell.
The library is in the same parent directory as my android studio project.
I did put these lines into my settings.gradle, without success.
include ':abc'
project(':abc').projectDir = new File(rootProject.projectDir, '../abc ')
This apparently works for library-projects which include gradle, but apparently not for libraries without gradle.
The result is this gradle sync error:
Unable to resolve dependency for ':app#debug/compileClasspath:' Could not resolve project :abc
In the dependencies section in build.gradle of your app module, add below.
implementation project(path:':abc' , configuration: 'default')
And in settings.gradle, only include ':abc' should be enough.
For anyone reading this... my conclusion so far: It is apparently not possible to use such a library (from Eclipse) without modifying those a little bit. I did these changes to get them working so far:
inside the src directory, make the directories main/java/ and move the package with the source codes to there.
write a build.gradle file in the root and define the module dependencies in it.
move the AndroidManifest.xml into src/main/
I'm trying to install the supertooltips library and I fail every time.
I followed many tutorials, but I ended up with
Error:Configuration with name 'default' not found.
Are all the folders and files in the zip necessary, or do I have to put a specific folder in my library folder "myproject/mylibs"? And when I try to add the library from file>new>import module or right click project > new > module > import Gradle project and choose the library; it says project already contains module with this name "app" folder.
I'm using the Android Studio 1.5.
Just add this to your dependencies in your Module:app build.gradle:
dependencies {
compile 'com.nhaarman.supertooltips:library:3.0.+'
}
Simply add that line and then just rebuild the project and the library will be added.
I am developing Android app with gradle project. My teammates use ADT, and I do Android Studio and I would like to try my best not to force limiting IDE for others.
As far as I know, ADT needs to have local dependencies (.jar or local lib).
Also if I have main project and local library which contains same local jar files, it cannot build with gradle due to "IllegalArgumentException: already added".
Settings below works fine with gradle and Android Studio but not for ADT, support v13 is not found.
Is there any way to make build works for gradle, Android Studio and ADT ?
Please let me know if you need more information.
My project setting looks like
settings.gradle
include: ':MyProj'
include: ':libs:PagerSlidingTabStrip'
build.gradle (MyProj's)
.....
dependencies {
compile 'com.android.support:support-v13:13.0.+'
compile project(':libs:PagerSlidingTabStrip')
}
.....
build.gradle (PagerSlidingTabStrip's)
.....
dependencies {
compile 'com.android.support:support-v13:13.0.+'
}
.....
You will have to do the following:
Make an Eclipse project for MyProject and libs/PagerSlidingTabStrip
In MyProj, create a libs folder and dump in it both support-v13 and support-v4.
Do NOT change build.gradle to dep on the content of libs/ or you'll have a duplicate class file issue.
This is manageable if you have only one lib project and few dependencies. If your setup become more complex it'll become impossible to manage (hopefully by then we have Gradle support in Eclipse)
I created a fresh project in Android Studio which uses external library (JAR). I put this in modules's build.gradle:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/mylib.jar')
}
But, when using Android Studio editor, it says there are some errors in my code and marks imports and variables (which use this library). It doesn't build properly saying that it cannot find one or another class. However, when I go to project's directory in terminal and execute gradlew manually, it builds APK and it (the APK) install and works just fine.
What am I missing? Is there any another setting in my project which is used for library detection?
Android Studio currently does not automatically sync your Gradle build files with your Android Studio (.iml) files. However, version 0.1.3 added a new sync button to the toolbar that will do this manually.
It's mentioned in the second bullet point of this blog post.
There were a lot of fixes in the Gradle project import and build
areas. There is now a "sync" button in the toolbar which will reimport
the Gradle project state into your Android Studio project. Use this
after editing your Gradle files, for example to add a library. In the
future we will more automatically handle state syncing, but for now
this is the simplest way to keep the IDE up to date with project
structure changes made to the Gradle files.
I've got such a problem
I have to include external java project into my android build.
The project structure is:
Alpha - project with shared classes and libs.
Beta - android project that uses files from alpha
Gamma - desktop java project that uses files from alpha.
Everything works fine on Eclipse, but I need it to work on Jenkins.
I'm using Google Android SDK (android update project command) to create a build.xml, and then I'm using google targets to do what I need (build, emma, clean and so on)
The problem is that this build.xml does not include files and libs from alpha project, so it basically failes at first line of beta build task.
My question is:
How to properly add alpha project as a dependency for a googles generated build.xml file?
Should I compress alpha to .jar and then add it somehow to beta (how?)
Should I just link it somehow?
Thanks for all help.
[I'm new to ant scripting so please write in plain engish:P]
Yep, this sucks! When using Jenkins and sharing one lib-project on different projects, you'll have to compile your lib-project (alpha), as you already mentioned, copy the jar to the respective directory of both projects, and link them in the Build Path Settings.
This is quite a lot of ANT-Stuff, you'll have to look into, but don't get discouraged, it ain't rocket science :)
Basically you have to do this:
Create an Ant-script that compiles your shared project, and copies it to some lib-directory in both projects
Link the Jar in the Build Path of your desktop and android project
For Jenkins: Customize android's build.xml (e. g. add a new target), so that it executes the lib project's build.xml (compile the project and copy the jar).
Run it on Jenkins
If you don't want to compile the shared project (manually) each time before you run your android or desktop project in eclipse, you should add the shared lib's build.xml with the respective targets to the projects' builder settings (in Eclipse -> right click on Project -> Properties -> Builders -> add the new builder between the Java and the Android package builder).
Sorry dude, I don't know any other way. Maybe there is another solution out there, I haven't used Jenkins for a year.