How to add ActiveAndroid ORM to Gradle?

空扰寡人 提交于 2019-12-23 12:28:35

问题


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:


回答1:


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') 
}



回答2:


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




回答3:


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'




回答4:


I can't answer the comment since I don't have enough rep yet, but make sure you sync your project with your gradle files again after adding the .jar to your dependencies.

Tools > Android > Sync Project with Gradle Files




回答5:


  • 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:


Bit of an old question but having just run into this issue as I'm getting up to speed with both Android Studio/Gradle and AndroidActive, the documentation tells you what you need to add, but expects you to know how to add it. Basically in the build.gradle for the app (not the project). Add the repositories at the top of the file (if it doesn't exist already) and add the compile statement to the end of the dependencies section. I've attached screen shot of my Gradle file that worked.




回答7:


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
  }
}



回答8:


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


来源:https://stackoverflow.com/questions/21458956/how-to-add-activeandroid-orm-to-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!