将 Google Play 服务添加到非 gradle Android Studio 项目? [英] Adding Google Play Services to non-gradle Android Studio project?

查看:30
本文介绍了将 Google Play 服务添加到非 gradle Android Studio 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有为 Android Studio 构建的 gradle 的现有项目我正在尝试导入 Google Play 服务以修复java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable 异常.

I have an existing project that was built without gradle for Android Studio and I'm trying to get Google Play Services imported to fix a java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable exception.

唯一的问题是它似乎不可能......我已经考虑将它移植到gradle 但代码库相当大(40 多个活动),这将是一个对于像我这样从未使用过 gradle 的人来说,这是一场噩梦.

The only problem is it doesn't seem possible... I've considered porting it to gradle but the codebase is rather large (40+ Activities) and it would be a nightmare for someone like me, who's never used gradle before, to accomplish.

我正在尝试从 SDK 导入 Google Play 服务项目,但它永远挂起创建 gradle 文件".

I've trying importing the Google Play Services project from the SDK but it hangs forever "creating gradle files".

之前有没有人有将这个库加载到非 gradle 项目的经验?

Anyone have any experience loading this library to a non-gradle project before?

顺便说一句,我已经尝试将项目加载到 Eclipse 中,看看我是否可以做到那样的东西,但构建路径自毁到我花了几个小时的地方试图对它们进行分类无济于事.

As an aside, I've tried loading the project into Eclipse to see if I could do something that way, but the build paths self-destruct to where I've spent hours trying to sort through them to no avail.

推荐答案

SDK/Extras 目录复制库

Copy the library from the SDK/Extras Directory

  1. 使用您的 SDK 管理器下载 Google Play 服务 - 它可以在 Extras 目录下找到.

  1. Use your SDK Manager to download the Google Play Services - it'll be found under the Extras directory.

转到您的 Android SDK 目录并找到 google-play-services_lib 目录,对我来说这是在 Android Studio 包中:

Go to your Android SDK directory and find the google-play-services_lib directory, for me this was in the Android Studio package:

/Applications/Android Studio.app/sdk/extras/google/google_play_services/libproject/google-play-services_lib/

将此整个目录复制到您项目的libs目录中.

Copy this entire directory to your project's libs directory.

像往常一样将其添加为模块依赖项.(对于 Android Studio,请参阅下面的分步说明.)

Add this as a module dependency as you normally would. (For Android Studio, see below for step-by-step instructions.)

您还需要将 meta-tag 添加到您的 AndroidManifest.xml 文件中,如下所示:

You'll need to add a meta-tag to your AndroidManifest.xml file as well, that looks like this:

<meta-data android:name="com.google.android.gms.version"android:value="@integer/google_play_services_version"/>

利润和派对?

Android Studio 步骤

在您的 libs 目录中添加库项目作为模块依赖项的步骤.

Android Studio Steps

Steps to add the library project as a module dependency once it's already in your libs directory.

  1. 文件 >导入模块.

选择 libs 目录下的 google-play-services_lib 目录.

Select the google-play-services_lib directory under your libs directory.

确保 Create module from existing sources 被选中,然后单击 Next 直到完成向导.

Ensure Create module from existing sources is selected and click Next until you finish the wizard.

Project Structure > Modules(最左边)> 选择你的应用 > Dependencies 标签 > + > 模块依赖 > google-play-services_lib.

Project Structure > Modules (far left) > Select Your App > Dependencies tab > + > Module Dependency > google-play-services_lib.

项目结构 > Modules(最左边)> 选择google-play-services_lib > Dependencies 标签 > + > jar 或目录... > 查找并选择 libs/google-play-services_lib/libs/google-play-services.jar.

Project Structure > Modules (far left) > Select google-play-services_lib > Dependencies tab > + > Jars or directories... > Find and select libs/google-play-services_lib/libs/google-play-services.jar.

确保点击此依赖项的Export复选框.

Make sure you click the Export checkbox for this dependency.

利润和派对?

非常感谢 Adama Speakman 的 post 了解具体的 Android Studio 步骤.

Many thanks to Adama Speakman's post for the specific Android Studio steps.

日本

这篇关于将 Google Play 服务添加到非 gradle Android Studio 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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