Best way to add dependency for Wire using Gradle in Android Studio

杀马特。学长 韩版系。学妹 提交于 2019-12-24 19:28:11

问题


I'm using Square's Wire library for my Android app, using Android Studio with Gradle.

I originally added the wire-runtime-1.2.0.jar into a libs folder in my module, and added the dependency to Gradle like this in my build.gradle file:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

That worked fine.

I'm new to Gradle and Android Studio, but based on the way I'm depending on the Google Support and Play Services libraries, I thought I might be able to remove the wire-runtime-1.2.0.jar library from my repository and just declare a dependency like this (the line is from the Maven repository):

dependencies {
    compile 'com.squareup.wire:wire:1.0.0'
}

But if I do that then I hit this error:

Gradle: package com.squareup.wire does not exist

Is there a way to set up this dependency without importing the JAR file directly? Or does that only work for libraries that you can install through the SDK Manager?


回答1:


Some packages, like com.squareup.wire, have multiple artifacts in Maven Central. You need to choose the right one for your needs. In this case, the equivalent of wire-runtime-1.2.0.jar is the wire-runtime artifact, not the wire artifact.

Here's what your dependencies section should look like:

dependencies {
    compile 'com.squareup.wire:wire-runtime:1.2.0'
}


来源:https://stackoverflow.com/questions/20130471/best-way-to-add-dependency-for-wire-using-gradle-in-android-studio

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