android - 如何在 Android Studio/IntelliJ 中导入 Maven 依赖项?

标签 android intellij-idea android-studio

我使用 Android Studio 中的默认向导创建了一个新的 Android 项目。编译并将应用程序部署到我的设备。一切都很好。

现在我想导入一个在 Maven 上可用的外部库。 (http://square.github.io/picasso/)。我去了模块属性,并添加了一个 Maven 库。它正确显示在依赖项列表中。此外,它显示在编辑器中,我可以在代码中正确使用它。

但是,在编译时,我收到 Gradle 错误: 找不到类(class)

有什么想法吗?

最佳答案

我以springframework android神器为例

打开 build.gradle

然后在apply plugin的同级添加以下内容:'android'

apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
   compile group: 'org.springframework.android', name: 'spring-android-rest-template', version: '1.0.1.RELEASE'
}

您也可以将此表示法用于 maven Artifact

compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'

您的 IDE 应在“外部库”下显示 jar 及其依赖项 如果它没有出现,请尝试重新启动 IDE(这发生在我身上很多次)

这是您提供的有效示例

buildscript { 
    repositories { 
        maven { 
            url 'repo1.maven.org/maven2'; 
        } 
    } 
    dependencies { 
        classpath 'com.android.tools.build:gradle:0.4' 
    } 
} 
apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies { 
    compile files('libs/android-support-v4.jar') 
    compile group:'com.squareup.picasso', name:'picasso', version:'1.0.1' 
} 
android { 
    compileSdkVersion 17 
    buildToolsVersion "17.0.0" 
    defaultConfig { 
        minSdkVersion 14 
        targetSdkVersion 17 
    } 
} 

关于android - 如何在 Android Studio/IntelliJ 中导入 Maven 依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16595287/

相关文章:

java - ImageView 折叠并且不显示创建的缩略图

intellij-idea - Gradle 找不到 Antlr token 文件

python - PyCharm 能否自动生成 __eq__() 和 __hash__() 实现?

android - 将 Activity 结果传递到 React Native 模块中

Android in app billing v3 响应不包括 orderId

java - IntelliJ 插件 : maven, gradle 和 travis-ci

android - 将现有代码分解为 java 和 android 模块

android - 在 32 位系统上升级 RAM 以提升 android studio?

导致 UNEXPECTED_TOP_LEVEL_EXCEPTION 的 Android Studio Google 端点

android - 禁用时更改 EditText 下划线