简体   繁体   English

在Studio中使用android.support.v4.app(或任何support.lib)

[英]using android.support.v4.app (or any support.lib) with Studio

Still feeling my way around Android Studio. 仍然对Android Studio感到自己的方式。 Looking at a bunch of tutorials and examples out on the web – and I'm finding out that studio must have evolved quiet a bit since it's 1st beta release and that many (perhaps most) of the information scattered out on the web references earlier versions of studio then what I'm currently running and some of the information may no longer apply and even be complexly wrong for my current version of Android Studio. 看一看网络上的大量教程和示例,我发现自从第一个beta版本发布以来,studio一定已经安静下来,并且网上散布的许多(也许大部分)信息都引用了早期版本。而不是我当前正在运行的Studio的状态,并且某些信息可能不再适用,甚至对于我当前的Android Studio版本来说也是错的。 I'm currently running 我目前正在跑步

  • Android Studio 1.1,0 Android Studio 1.1,0
  • Build AI-135.1740770 built on February 18, 2015 2015年2月18日建立的AI-135.1740770版本
  • JRE 1.7.0_71614 amd64x JRE 1.7.0_71614 amd64x

and my SDK is up to date as of 4/4/15 并且我的SDK是最新的,截至2015年4月4日

This has left me with a bunch of questions. 这给我带来了很多问题。 My current question is about 我当前的问题是关于
import android.support.v4.app.Fragment; 导入android.support.v4.app.Fragment;

Some tutorials say that when using studio, you need to find the .jar file and manually copy it into your projects .lib folder. 一些教程说,在使用Studio时,您需要找到.jar文件并将其手动复制到项目的.lib文件夹中。 Other examples just use the import statement and never talk about needing to manually copy it into your projects .lib folder. 其他示例仅使用import语句,从不谈论需要手动将其复制到项目的.lib文件夹中。 Or adding it to the manifest file. 或将其添加到清单文件中。

Which method is correct? 哪种方法正确?

In your app gradle file, you will see a bunch of stuff like android, dependency etc. 在您的应用gradle文件中,您会看到很多东西,例如android,dependency等。

Dependency is the place you add your libraries. 依赖关系是您添加库的地方。 For eg. 例如。

dependencies {
    compile 'com.android.support:support-v4:21.0.3'
}

We use compile to make sure that the project is ready to use in your project and you also see the support-v4:21.0.3 , you can always get the correct version no from the dev website or some external souce. 我们使用compile来确保该项目已准备好在您的项目中使用,并且您还会看到support-v4:21.0.3 ,您始终可以从dev网站或某些外部来源获得正确的版本号。

Same way you add dependency for v7 and its gonna be like : 以相同的方式为v7添加依赖项,其方式如下:

dependencies {
        compile 'com.android.support:support-v7.SOME VERSION NAME'
    }

You probably dont have to use the v4 lib since you are already adding the dependency for app compat. 您可能不必使用v4库,因为您已经为应用程序兼容性添加了依赖项。 After adding the dependency, trying to clean the project. 添加依赖项后,尝试清除项目。

To add your own built library project, you will point your app project to the library project you have created and add that to your dependency as the same process as above. 要添加自己的内置库项目,请将您的应用程序项目指向已创建的库项目,并将其添加到依赖项中,方法与上述相同。

If you want to know more about adding dependency to you android projects, also refer to this link How do I add a library project to Android Studio? 如果您想了解有关向您的android项目添加依赖项的更多信息,请参阅此链接如何将库项目添加到Android Studio? .

Hope this solves your problem. 希望这能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM