Installing Android SQLite Asset Helper - android

I need to use my ready made database. Search for solution on internet did not work until I decided I will use the mentioned library found here. However, I found it hard to use the library in that installation procedures are really shallow for beginners.
I will appreciate a step by step procedure on how to use it with Android Studio. In my struggle I tried copying sources to main/libs and adding the line to gradle did not work. I use API 19 if that helps.
UPDATE
here is my build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
}
}
trying to compile the project I get error
Error:(9, 0) No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [com.readystatesoftware.sqliteasset:sqliteassethelper:+]
Possible solutions: module(java.lang.Object)

This is an old question, but it doesn't seem to have a proper answer, and I found it while trying to install SQLiteAssetHelper myself, so I thought I should share my experience, according to the instructions found here.
Like most inexperienced Android Studio users, I thought I should Download ZIP from the GitHub repository and place it somewhere in my PC. Turns out this is not the way to Install SQLiteAssetHelper, if you are using Gradle which is a Build system integrated in Android Studio.
What you need to do is simply described in the GitHub repository Setup section. So here is a Step-by-step guide, with some additional information:
1) Make sure that your Gradle is not in Offline Mode. (In Android Studio which is currently at version 2.2.2, go to File > Settings > Build, Execution, Development > Gradle and uncheck Offline Work in case that is checked. (This is only required for your first Sync)
2) In your Android Studio Project Navigator (on the left) you should see an item entitled Gradle Scripts. Expand it, and you should find a build.gradle file. If you see two such files, there should be a comment in a parenthesis next to each one saying Project: YourProjectName and Module: App.
If you open the one saying Project: YourProjectName you should see the following comments:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
So, you should choose the one saying Module: App, at the end of which you should see something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}
At that point, you should just add the code pointed out in GitHub, like this:
dependencies {
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}
That's all. To start using it, you just have to extend the SQLiteAssetHelper class, pretty much like extending SQLiteOpenHelper.

Related

Android Studio Gradle dependency doesn't show up in External Libraries

I'm using Android Studio 3.0.1 and I'm trying to add an online dependency and while Gradle initially syncs without a problem it doesn't show my dependency in External Libraries and my code that references the dependency doesn't work.
Here's a snippet of what my build.gradle file looks like:
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/groups/public/' }
}
dependencies {
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
}
I'm pretty new to android development (took over an existing project from a dev who quit without leaving any documentation) so I'm not sure if this is a mistake with how to add a project dependency or if there is a problem with the dependency that I'm trying to add. Any help would be greatly appreciated!
I was able to get this to work by changing the dependency declaration to:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT', classifier: 'jar-with-dependencies'
The library artifacts up on the repository include an apklib and a JAR with a special classifier. The apklib format is not supported by Android Studio, and unfortunately the classifier on the JAR means that it's not accessible simply using the group-name-version format when declaring dependencies.
Your build.gradle file seems fine. If you want to keep the library specified as an external library, you can try and define the dependency using the alternative notation, replace:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
with:
compile 'com.fortysevendeg.android:swipelistview:1.0-SNAPSHOT'
The alternative approach is to download the jar file yourself and use it as a local dependency. If you navigate to the maven repository you can inspect the package which is included as a dependency and download the jar directly. Place the jar file in the libs folder of your project and add the following to your build.gradle file:
compile fileTree(dir: 'libs', include: ['*.jar'])
For further details on how to configure the dependencies of your gradle project, check out the Android Studio documentation here.
Based on the information you have provided, this should fix your issues. If this does not solve the error then there may be other issues with the project.
Your dependencies should not placed in the top-level build.gradle file where the repositories are defined. There is even a comment in that file that says so, by default.
You app dependencies should be the module's build.gradle along with the others like android-support
Additionally, that library is very old, and is a SNAPSHOT build, meaning it isn't meant to be generally used in a release environment. You should find an alternative... And there are plenty of other ListView swiping ones

Why won't Android Support Libraries work in my project?

Using Android Studio, I followed the steps at https://developer.android.com/tools/support-library/setup.html as acurately as I could, but it told me the following error:
Error:Could not find method compile() for arguments [com.android.support:appcompat-v7:18.0.+] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#18899229.
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
But I have already installed the Support Repository and Library! Since I also got an error saying compile doesn't belong in the dependencies block, so I changed it to classpath, and got the following, similar error:
Error:Could not find any version that matches com.android.support:appcompat-v7:18.0.+.
Required by:
:ExpenseTracker:unspecified
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
As you can see here, it still thinks the ASR isn't installed, but as the screenshot proves, it is. So what am I doing wrong here?
I think you're placing these lines in the wrong file.
They should go in the module's build.gradle file, not in the project's one (which this would seem to be, from the screenshot).
Also, the dependencies tag should not be a child of anything else. something like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
...
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-v4:18.0.+"
...
}
EDIT Did you see the comment? :)
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
My problem was that after letting Android Studio upgrade the Gradle plugin to the latest version, it had messed up the dependency section of my module's build file. It had concatenated the dependency declaration lines together (except for the lines that were mere comments). Separating the lines (placing each dependency declaration in a single line) fixed the issue.

add external jar to an android project *manually* (without eclipse etc)

my problem is simple:
in the web there are numerous ways and tutorials on how to include jars in an android application through eclipse, android studio etc.
I want to do it manually; so, I want to know which files do I have to edit to bind my app
with the specific jars.
in the web there are numerous ways and tutorials on how to include jars in an android application through eclipse, android studio
That is because the use of third-party libraries is tied to the build system being used to build the app.
I want to do it manually
It is unclear what "manually" means in this context.
If you mean that you are using Ant, just put the JAR(s) in your project's libs/ directory, and you are done. Note that this will work with Eclipse as well.
If you mean that you are using Gradle, you will need something like this in your build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
Or, if the JARs can be found in a Maven or Ivy repository, you can reference those as well, by defining the repository in the repositories block and then simply specifying the artifact in the compile directive:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:11.0.2'
}

How do I add Guava to my Android Studio project?

First and foremost, I am aware of the existence of this question - How do I add a library project to Android Studio? - and unfortunately, it has not helped me.
My goal is rather simple. I want to write an Android app using the Android Studio IDE (0.2.11), and the Guava libraries in my code.
I do not know Gradle, I've only started using Android Studio and my Visual Studio/C# background has dumbed me down, for which I apologize (in that Mickey Mouse world, you typically just add a library reference and off you go).
I will document my steps with screenshots. I mostly followed advice given in this answer.
I created a libraries folder under my project folder.
I cloned Guava repository into it.
Files successfully appeared.
I went to Project Structure and selected Import Module.
I selected Create module from existing sources and agreed to all the default choices.
I updated my settings.gradle file to include ':libraries:guava', ':Test':
And my build.gradle file with compile project(":libraries:guava"):
But all I'm getting whenever I'm trying to rebuild the project is:
Error: Gradle: A problem occurred configuring project ':Test'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
I did try putting a build.gradle as below in the guava folder:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
(as the aforementioned answer says).
I have googled up and down to find the "correct" build.gradle for Guava.
https://code.google.com/p/guava-libraries/wiki/UseGuavaInYourBuild - didn't help me, either.
I did try countless things which I will not describe here as they were rather haphazard - I tried adding a module dependency, I tried turning Use auto-import on in Gradle settings, etc.
I know it's not a way of solving issues and I promise I will diligently read Gradle's User Guide from 1 through 5.4.2 to 7.3, but I can't believe this is really prerequisite to achieve something as unremarkable as merely adding a library to a project? Why is there no default build.gradle file from which one could start to fiddle with all sorts of things if necessary?
And the real question - how do I create an app (in Android Studio) that builds, actually runs on an Android device and on the top of that allows me to use Guava so I could sort a map by values without writing 50 lines of code? :)
Sorry about the chatty tone of my question, I know the drill around here, it's just my way of venting my frustration off.
Judging by how many votes were casted for questions and answers that tackled similar issues, I'm sure I'm not the only one who would benefit from some more instructions. I would start a bounty on it straight away, but the rules forbid me.
If you just need to use a stable, released version of the Guava libraries, importing it is extremely easy.
Just go to the build.gradlefile of the module where you want to use the library (i.e GuavaTestProject/GuavaTest/build.gradle) and, right after
repositories {
mavenCentral()
}
add a Maven dependency:
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '15.0'
}
Rebuild your project if needed and that's all (tested right now with a fresh project created with Android Studio 0.2.13).
If you really need to include the source code of the Guava library and compile it yourself as a module of your Gradle build that's an entirely different problem because Guava is build with Maven and so you need to move the Guava build system from Maven to Gradle, which I think is overwhelmingly complex for your goals.
If you just need to browse the source or view it while debugging, what I would do is:
Download Guava source code on a separate folder:
git clone https://code.google.com/p/guava-libraries/
git checkout v15.0
When Android Studio doesn't find the sources, click on "Attach sources" and point to this alternative location.
I think if you don't need to actually modify and compile Guava source code this is the easiest solution.
dependencies {
compile 'com.google.guava:guava:19.0'
}
Source: https://github.com/google/guava
EDIT:
As of v22, there's specific guava version for Android.
dependencies {
compile 'com.google.guava:guava:22.0-android'
}
* Thanks Sam :)
Thats a lot of info in your question.
I am using Guava too. But I don't remember going through any of this trouble..
Guava is available on the mavencentral. So adding guava to your project should be fairly simple. AFAIK, you do not need to checkout, build and add a project dependency etc..
See gradle file for my app below.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
// Dependencies
dependencies {
compile fileTree(dir: 'libs', include: '*.jar') // jar files under the libs folder.
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar' // actionbarsherlock,
compile 'com.android.support:support-v4:18.0.0' // android support lib
compile 'com.google.code.gson:gson:2.2.4' // google GSON
compile 'com.google.guava:guava:14.0.1' // guava 14.0.1
}
do not use the full guava library, use the version specific for android,
dependencies {
compile 'com.google.guava:guava:23.0-android'
}
In Android Studio 0.3.0 This is now working as it should on Mac. See the release notes for additional options in adding libraries
http://tools.android.com/recent/androidstudio030released
I have been working on Windows now and there are two options
Right click on a jar in libs and you have an add to library
Or you can push F4 and get to open library settings so it seems you do not have to struggle as much on Windows as on a Mac
This is what I did. Please read to the end since it works inconsistently and if you do not see the blue arrow first try there is a resolution. First I created a libs folder. I do not think this is needed though but it is a habit.
First try go to File , Project Structure.
If you see a little blue arrow at the top left push it and you will go to the screen where you can add a library
If you manage to get to this screen below push the plus sign and add the library.
You may also see a red line at the bottom saying Guava not used with a light bulb. This fill add the dependancy to the Gradle Build File
IF YOU DONT SEE THE BLUE ARROW
GO instead to File, Other settings, Default project structure.
From that screen you can add the library
Then go back to project structure and add it. The thing is that it will remain as a default for all your projects so you can add and remove it for each individual project via the project structure menu. I am not sure if this is a bug in Android Studio the fact that you can be blocked from adding it to the individual project without changing the default.
For Android Studio 3.2.1:
Click the File/Project Structure menu (ctrl+alt+shift+S). Press the + button in the Dependencies tab from the app menu to add a Library dependency.
Look for com.google.guava:guava:(whatever number is the most recent one) and add it.

Use android-maps-utils in Android Studio

I am trying to use this library [1] in an Android project either with Android Studio or with ADT. But it doesn't work at all. In ADT I don't know how to handle gradle stuff and in Android Studio, when I try to "Import Project", I get the error "Could not find com.google.android.gms:play-services:3.1.36.
(don't have enough reputation to post picture, it's on imgur with xswZ3.jpg)
I am not familiar with gradle and I only have a vague idea of what it does but all I want is to use something like BubbleIconFactory f = new BubbleIconFactory(this) in my own project.
Any help is appreciated!
[1] https://github.com/googlemaps/android-maps-utils
Perhaps your problem is needing the repositories outside of the buildscript block.
The repositories internal to the buildscript is for managing the gradle dependency itself, I believe. Here's how I resolved my problem with google-maps-utils as a library dependency. Hopefully this helps. I included my maps and support-v4 libs too.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.2+'
}
You'll need to install the "Google Repository" from the Android SDK manager.
See demo/build.gradle for an example.
You can, of course, copy the library directory and use it like any other Android library project.
Let me know if this helps!
Chris
Steps:
First File>Project Structure>Click Plus Button >Import Graddle Project>Select the file(library folder) from the location where downloaded>CLick Ok.
Add this code to dependencies to that app module build.gradle file(remember there are two build.gradle files) :
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Copy gradle.properties file contents of that Android-maps-util Library project app(found inside that project library folder) TO
gradle.properties file of your project(Simple copy and paste of content to the editor).
Click Sync Project with gradle files button. And you must be fine!

Categories

Resources