【问题标题】:cant import some libraries in android studio无法在 android studio 中导入一些库
【发布时间】:2018-09-09 09:16:06
【问题描述】:

我正在尝试导入一些库,如 Picasso 等,但 Android Studio 显示此消息。

这里是 build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "com.example.mypc.urumcafe"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
       'proguard-rules.pro'
       }
    }
  }

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.volley:volley:1.0.0'
compile 'com.amitshekhar.android:android-networking:1.0.1'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}

我只想导入“com.amitshekhar.android:android-networking:1.0.1”,但正如您在上传的图片中看到的那样,出现“无法解决”错误。 那么我该如何解决呢? Picasso lib 也是如此。 谢谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    将您的构建工具版本更新为 27.0.3 并将相应的依赖项更新为 sdk 版本 27。

    这是更新后的 build.gradle,它运行良好。

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 27
        buildToolsVersion "27.0.3"
        defaultConfig {
            applicationId "com.example.mypc.urumcafe"
            minSdkVersion 17
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'),
                        'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
                {
                    exclude group: 'com.android.support', module: 'support-annotations'
                })
        compile 'com.android.support:appcompat-v7:27.1.1'
        compile 'com.android.support.constraint:constraint-layout:2.+'
        compile 'com.android.volley:volley:1.0.0'
        compile 'com.amitshekhar.android:android-networking:1.0.1'
        compile 'com.android.support:design:27.1.1'
        testCompile 'junit:junit:4.12'
    }
    

    【讨论】:

    • 生病测试它.tnx
    • 只需将以下代码复制粘贴到您的 build.gradle 中
    • 它出现“在:C\Android\sdk 中找不到带有哈希字符串'android-27'的目标
    • 点击显示包详情并下载android SDK platform 27
    【解决方案2】:

    该库的最新版本是 1.0.2。 使用它再试一次:

    com.amitshekhar.android:android-networking:1.0.2
    

    【讨论】:

      【解决方案3】:

      您可能缺少 Maven Central(或用于 v1.0.2jitpack.io)存储库:

      allprojects {
          repositories {
              google()
              mavenCentral()
              jcenter() 
          }
      }
      

      【讨论】:

      • 你能告诉我更多吗?
      • @Shayanebrahimzadeh 还有什么要说的?就是这样......这进入项目级别build.gradle。添加后,您只需同步,它应该获取两个库。请接受我的回答,以防万一,我会假设。
      • 最初是这样的。 allprojects { repositories { jcenter() } } 然后我将其更改为 allprojects { repositories { mavenCentral() } } 但现在我可以看到更多错误
      • @Shayanebrahimzadeh 更新我的答案;它们的顺序可能会有所不同,但通常这些应该是正确的。
      猜你喜欢
      • 2016-01-19
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多