How to add ActiveAndroid ORM to Gradle?

2019-06-24 01:21发布

I'm building an Android app in which I want to use the ActiveAndroid ORM. In the readme I read instructions on how to include it in Maven or ADT, but I'm using/trying to learn Android Studio with Gradle. So I guess I need to insert ActiveAndroid as a dependency. in my build.gradle file on these lines:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

I don't really know what kind of string/url I should use so that Gradle can automatically find ActiveAndroid and compile it into my project.

Sicne I'm kinda lost; could anybody give me a tip here on how I should be tackling this?

[EDIT] I now build the jar and compiled it using the suggested compile files('libs/ActiveAndroid.jar') (I have no version name in my jar file). It now builds successfully, but I still cannot import classes from it. See the image below: enter image description here

8条回答
戒情不戒烟
2楼-- · 2019-06-24 02:01

Download the JAR from this link

OR

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }

}

compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'

查看更多
Summer. ? 凉城
3楼-- · 2019-06-24 02:02

My full build.gradle(app) with ActiveAndroid:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {

  }
}

repositories {
  mavenCentral()
  maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

apply plugin: 'com.android.application'

dependencies {
  compile 'com.michaelpardo:activeandroid:+'
  // other dependencies
  compile fileTree(dir: 'libs', include: '*.jar')
}

android {
  compileSdkVersion 24
  buildToolsVersion '24.0.0'
  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName '1'
    multiDexEnabled true
  }
}
查看更多
Anthone
4楼-- · 2019-06-24 02:04

Maybe this is new since this question was answered, but this is in the getting started guide:

Modify your build.gradle to include:

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'

https://github.com/pardom/ActiveAndroid/wiki/Getting-started

查看更多
仙女界的扛把子
5楼-- · 2019-06-24 02:07
  • Please make sure dependencies are added in individual module build.gradle file and NOT the common build.gradle file?
  • Also, under "Open Module Settings" make sure the dependencies are present under the "dependencies" tab of the app.
  • After you add the jar file to "libs" folder, build again and check if there is a build.gradle for ActiveAndroid module.This is what it should look like or a variation of this:

configurations.create("default")

def jarFile = file('ActiveAndroid.jar')

artifacts.add("default", jarFile)

查看更多
何必那么认真
6楼-- · 2019-06-24 02:08

Try these steps:

  • Go to this link - https://oss.sonatype.org/
  • Search for michaelpardo
  • A list which also include activeandroid would have came up
  • Click on the specific row and download the jar file
  • Put that jar file in libs folder and use Add to library option from Android Studio
  • Compile and it should work
查看更多
欢心
7楼-- · 2019-06-24 02:12

Give this a go - download the JAR from here

Add it to your libs folder.

Change your dependancies to look something like this

dependencies {
    compile 'com.android.support:appcompat-v7:+'

    compile files('libs/ActiveAndroid-3.3.jar') 
}
查看更多
登录 后发表回答