支持VS"真正的"图书馆"类找不到" [英] Support vs "real" libraries and "classes could not be found"

查看:415
本文介绍了支持VS"真正的"图书馆"类找不到"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用RecyclerView在测试项目时,我将要尝试的是Android 5.0棒棒糖,我看到了下面就谷歌网站:

1),令我百思不解的是,他们使用的支持的事,而不是真实的东西在API 21.我期待不使用,因为我运行在设备上5.0的支持包提供的,有21 SDK下载和安装。为什么不能我只是用RecyclerView直接,无需使用支持...?

2)类无法找到
在Android Studio中,我得到这个错误:

元素RecyclerView在这里不允许没有进一步的信息。另外,如果我用如上张贴的例子中,我得到了同样的错误:

如果我点击修复构建路径,我看到的:

我一直在使用JAVA和Android这些问题,但该错误消息是不清楚。该SDK的路径(在SDK位置)是正确的。

这是我的gradle:

 应用插件:'com.android.application安卓{
    compileSdkVersion 21
    buildToolsVersion19.1.0    defaultConfig {
        的applicationIDse.snap code.loll​​ipoptest
        21的minSdkVersion
        targetSdkVersion 21
        版本code 1
        的versionName1.0
    }
    buildTypes {
        发布 {
            runProguard假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
    }
}依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
}

这是我的清单:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=se.snap code.loll​​ipoptest>    <采用-SDK安卓的minSdkVersion =21
        机器人:targetSdkVersion =21/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=。MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>< /清单>


解决方案

由于我完全破坏了我的第一个答案,让我们再次从顶级试试这个...


  

令我百思不解的是,他们使用的支持的事,而不是真实的东西在API 21条的规定。


在没有真正的事情。 RecyclerView 仅在Android的支持包,通过 recyclerview-V7 库项目/ AAR。

这是类似于谷歌如何包 ViewPager 支持-V4 支持 - V13 ), CardView cardview-V7 ),在Leanback的用户界面针对Android TV( 的Leanback-V17 )等。

Android的支持库不仅是一套反向移植的。它包括只能通过这些库提供的各种课程。除上述外,还有 NavUtils FileProvider ,以及其他各种类,都是本地到Android支持库。

所以,如果你想 RecyclerView 添加 recyclerview-V7 到您的项目,如通过Android的工作室:

或通过您的应用模块的的build.gradle

  {相关性
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.android.support:recyclerview-v7:21.0.0
}

When I try to use the RecyclerView in a test project when Im about to try out Android 5.0 Lollipop, I see the following on Googles site:

1) What puzzles me is that they use the support thing instead of the "real" thing as provided in API 21. I was expecting to not use the support-package as I am running 5.0 on the device, have SDK 21 downloaded and installed. Why cant I just use RecyclerView directly, without using the support...?

2) Classes could not be found In Android Studio, I get this error:

"Element RecyclerView is not allowed here" without further information. Also, if I use the example as posted above, I get the same error:

And if I click "Fix Build Path", I see:

I always have these problems using JAVA and Android, but the error messages are unclear. The path to the sdk is correct (under SDK Location).

This is my gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "se.snapcode.lollipoptest"
        minSdkVersion 21
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

and this is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="se.snapcode.lollipoptest" >

    <uses-sdk android:minSdkVersion="21"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

解决方案

Since I totally wrecked my first answer, let's try this again from the top...

What puzzles me is that they use the support thing instead of the "real" thing as provided in API 21.

The is no "real" thing. RecyclerView is only in the Android Support package, via the recyclerview-v7 library project/AAR.

This is akin to how Google packages ViewPager (support-v4 and support-v13), CardView (cardview-v7), the Leanback UI for Android TV (leanback-v17), etc.

The Android Support libraries is not just a set of backports. It does include various classes that are only available via those libraries. In addition to the above, there is NavUtils, FileProvider, and various other classes that are "native" to the Android Support libraries.

So, if you want RecyclerView, add recyclerview-v7 to your project, such as via Android Studio:

or via your app module's build.gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:recyclerview-v7:21.0.0'
}

这篇关于支持VS&QUOT;真正的&QUOT;图书馆&QUOT;类找不到&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆