Use library without gradle files in Android Studio - android

I am trying to import this library my Android Studio project, but am not having any luck because it doesn't have any gradle files. https://github.com/xibsked/android-numberpicker
I found these posts, (Using library products without gradle files in Android Studio, How to import project files without Gradle files into Android Studio) but they are either unanswered or the answers involve exporting from Eclipse, which isn't my case. I'm not migrating from Eclipse, just want to use this library.
Thanks!

That libary does appear to be published to Maven:
http://mvnrepository.com/artifact/net.simonvt/android-numberpicker/1.0.0
So you just need to add that dependency to your project's build.gradle file:
dependencies {
'net.simonvt:android-numberpicker:1.0.0'
}
If that's not an option for some reason, then you'll have to grab a copy of the source and import it into your project, as fractalwrench suggested.

in general you can do:
create a new module and copy the source in your project app/main/src
clone or copy the module library in your project and add the build.gradle file
In the second case just config the right source set in your build.gradle file
apply plugin: 'com.android.library'
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
In both scenario you have to add a module in your project:
root
|--app
|----build.gradle
|--library
|--build.gradle
|--settings.gradle
In settings.gradle just add:
include include ':library', 'app'
and in your app/build.gradle add
dependencies{
compile project(':library')
}

One option would be to include the source files directly in your project, by copying to your app/src/main/ directory. If you want to add an extra layer of separation, you could create a new module before copying the files in.

Related

How to implement native Google Play In-app billing in a libGDX project?

I was following this and stuck at "a. Navigate to src/main in the Project tool window."
Because I couldn't find src/main in my project structure (Neither in the explorer)
Like it is shown here:
I think it's because I'm working with a libGDX project.
I tried adding the Module directly under the src (As if I was not working in a android studio environment), but when I build my application, I don't see a generated file named IInAppBillingService.java anywhere.
If you open build.gradle in the android folder of your project, you will see the following block of Gradle code:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
This block configures where Gradle looks for source files. LibGDX uses this to customize the directory hierarchy which is why you are unable to exactly follow the steps given in the Android documentation.
Now the line aidl.srcDirs = ['src'] tells us that the project is configured so that all AIDL files can be placed directly in the src folder. So you can modify the step to navigate to src/main and instead just go directly to src. Follow the rest of the instructions from there. If Android Studio balks at any step, you may have to go directly to the file system using the command line or your favorite file explorer in order to create the folders and files that you need.
It appears you have done this and the second part (or maybe the primary part?) of your question is the location of the generated .java file from your AIDL source. Android Studio places all generated artifacts under the build directory. There is a build folder directly in the base directory of your project and one in each module. Search these for the generated file.

Cannot import an Android project from Eclipse to Android Studio after building a build.gradle file

I generated a Gradle file of an Android project from Eclipse, to keep working on the project in Android Studio. Then I imported the Gradle file to open the project in Android Studio, but very confusingly it failed to build the project, showing the following message.
Error:SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
I have been working on other Android projects in Android Studio with no problems in this issue, so I become too much confused. I also searched the questions regarding the same matter, but none of them seemed to clearly suggest the solution.
In order to make you better understand, I show you several things related to building the project.
1. build.gradle
apply plugin: 'com.android.application'
and
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:22.2.0'
}
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
2. local.properties
sdk.dir=/Users/marshall/android-sdks
The Android SDK is properly installed in that direction above. What should I do now?
IMPORTING ECLIPSE PROJECT IN ANDROID STUDIO:
If you want to import Eclipse Project in Android Studio:
1. Launch Android Studio and Select Import project (Eclipse ADT, Gradle, etc.)
2. Then nothing special just follow the instructions in the wizard.
NOTE: Just Make sure you have chosen the folder of Eclipse project that contains the src folder. And also ensure the target folder will be empty.
You don't need to create build.gradle or export any thing from eclipse as this steps are no longer needed to Android Studio

Android Studio -- Use Gradle with the 'traditional' ordering of files

I am building a project with Gradle, but, to maintain consistency with my coworkers' use of the Ant build system, I need to keep the old file structure. How do I refactor my project/file structure to the traditional one?
I thought this would be a common question, but I could not find any answers. Can Android Studio help me here?
How do I refactor my project/file structure to the traditional one?
Start with the traditional one in the first place. Don't change the files -- change build.gradle.
All of my CWAC libraries are published this way, using the legacy project directory structure, but with a build.gradle file (based on the one you can export from Eclipse) that teaches Gradle for Android where everything is.
For example, here is the relevant piece of the build.gradle file for my WakefulIntentService:
android {
compileSdkVersion 17
buildToolsVersion "19.1.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Here, we are configuring the main sourceset, from a Gradle perspective, telling it where all the different types of "source" come from. Most things, like the Java code, come from the src/ directory in the project, for example.
Some of this is unused in my projects (e.g., pointing the debug and release build types to look for their custom sourcesets off of a build-types/ directory), but I left it there from what Eclipse exported.

How do I "link source" in an Android Gradle project?

I'm migrating to using Gradle in Eclipse. My project links a source directory that I reuse in several other projects.
Now I want to be able to use a Gradle task to build or install my app, but I don't know how to specify the other source directory.
Right now, my Eclipse workspace looks like this:
workspace/
ParentGradleProject/
core/
src/
android/
src/
mySharedLibrary_src/
I tried this but it's still not seeing the external src directory. See second line under main:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', '../../mySharedLibrary_src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
...
}
You can't use Gradle as a build system for Android in Eclipse. The Android Gradle plugin is only supported in Android Studio/IntelliJ CE. This is because the plugin doesn't use normal Java sourceSets; it uses custom sourceSets that Eclipse's Gradle plugin isn't set up to understand. The failure you're seeing is from Eclipse not reading your sourceSet directive, falling back on its default, and only finding src.

Incorrect project module layout android studio gradle

The problem i am having is as follows: The root project of my android studio project should in fact be a module. I imported it ages ago from eclipse and it must not have created the common project -> module directory structure needed for gradle.
This is only now becoming an issue as i have to turn the main code-base into a library project and library projects with gradle can only be created within application modules and not the root project.
so basically my project:
should be looking more like this example that ive made:
I have tried adding the wrapping project folder, settings. gradle etc.. in windows explorer and building gradle but to no avail. Is there a way to add a new root to a project in android studio and turn the root into a module without breaking everything??
Note: Making a new project with the correct structure is not an option i dont think because my project is already a remote git repository on other production apps.. Any help would be greatly appreciated.
P.S: If gradle was my girlfriend, i would have broken up with her by now!!
Figured it out eventually. Adding the wrapping project folder, settings. gradle etc was the right thing to do. Turned out that my app build.gradle folder had the following redundant source set
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
This was preventing gradle from indexing my new main java directory folder and the new location of my app manifest.

Categories

Resources