【问题标题】:error: package com.android.annotations does not exist in android studio 2.3.1错误:android studio 2.3.1 中不存在包 com.android.annotations
【发布时间】:2017-09-25 01:57:23
【问题描述】:

我正在使用

import com.android.annotations.Nullable;

它正在编译并且应用程序正在运行

  • 安卓工作室 2.3
  • gradle 版本 2.14.1 和
  • android插件版本 2.2.3.

但是更新到之后

  • Android 工作室 2.3.1
  • gradle 3.3 版和
  • android插件版本2.3.1

它停止编译。我已经搜索了其他一些 SoF 问题,例如 this,但他们建议使用不同的包

import android.support.annotation.Nullable;

我想知道必须使用支持库包。如果是,它是如何与其他导入一起运行的?

我的应用程序 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
//        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath "io.realm:realm-gradle-plugin:3.0.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块构建.gradle

apply plugin: 'com.android.application'
//apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'


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'
    })
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-annotations:25.1.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
    compile 'com.android.support:design:25.1.0'
    compile 'com.pkmmte.view:circularimageview:1.1'
    compile 'com.android.support:cardview-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.github.aakira:expandable-layout:1.4.2@aar'
    compile 'com.google.maps.android:android-maps-utils:0.4.4'
    // retrofit library for networking calls
    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    // gson adapter for rxjava
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    // rxjava adapter for retrofit
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
    // rxandroid library
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    // rxjava library
    compile 'io.reactivex.rxjava2:rxjava:2.0.6'
    // sugar ORM library
    compile 'com.github.satyan:sugar:1.5'
    //    compile 'com.squareup.okhttp3:okhttp:3.5.0'
    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    // library for implementing Parcelable interface
    compile 'org.parceler:parceler-api:1.1.6'
    annotationProcessor 'org.parceler:parceler:1.1.6'
    compile 'com.github.eralpyucel:CircleProgressView:v1.1'
    // library for intercepting OKHttp3 api calls
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'me.relex:circleindicator:1.2.2@aar'
    //    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    // library to show view transition in pre-lollipop android version
    compile 'com.kogitune:pre-lollipop-activity-transition:1.3.3'
    // library for getting user location updates
    compile 'com.github.delight-im:Android-SimpleLocation:v1.0.1'
    // library for date time picker
    compile 'com.wdullaer:materialdatetimepicker:3.1.3'
    // for showing memory leaks
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
    // for viewing database in chrome
    debugCompile 'com.facebook.stetho:stetho:1.5.0'
    // n/w interceptor will show request url, header, body and response
    debugCompile 'com.facebook.stetho:stetho-okhttp3:1.5.0'
    debugCompile 'com.facebook.stetho:stetho-js-rhino:1.5.0'
    // realm support for stetho
    debugCompile 'com.uphyca:stetho_realm:2.0.0'
}

正如你在 build.gradle 中看到的,我已经评论了

//apply plugin: 'com.neenbedankt.android-apt'

我在 Android Studio 2.3 中使用的注释插件,更新后我将其删除,因为注释处理器是由 Android Studio 本身提供的。

所以我想知道为什么android studio 找不到

导入 android.support.annotation.Nullable;

更新后这个注释类是否存在于我之前使用的插件中?

【问题讨论】:

  • 你解决了吗?我有同样的问题。
  • @qbait 我只是更改了所有导入语句。还没找到解决办法
  • @prateek 你解决了吗?我在 Canary 8 中有同样的问题。stackoverflow.com/questions/45204273/…

标签: android annotations android-studio-2.3


【解决方案1】:

我也有这个问题,我有

import com.android.annotations.NonNull;

但找不到包。

所以我注释了那行并再次导入,它改为:

import android.support.annotation.NonNull;

终于成功了。

【讨论】:

    【解决方案2】:

    如果这不影响您的项目,您可以使用Android Jetpack。 For migration

    然后简单地替换这个:

    导入 android.support.annotation.{annotation}

    与:

    导入 androidx.annotation.{annotation}

    【讨论】:

      【解决方案3】:

      请在您的应用程序 build.gradle 中将您的 gradle 版本更改为 classpath 'com.android.tools.build:gradle:2.3.1',然后尝试

      【讨论】:

        猜你喜欢
        • 2017-03-15
        • 1970-01-01
        • 1970-01-01
        • 2016-08-14
        • 2014-12-12
        • 1970-01-01
        • 2020-07-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多