在 Android Studio 上设置许可验证库

Posted

技术标签:

【中文标题】在 Android Studio 上设置许可验证库【英文标题】:Setting Up the Licensing Verification Library on Android Studio 【发布时间】:2013-08-29 06:29:36 【问题描述】:

我正在尝试在 android Studio 制作的应用中实施 Google 许可验证。 遵循以下几行:http://developer.android.com/google/play/licensing/setting-up.html 似乎很重要:

作为将 LVL 添加为库项目的替代方法,您可以将库源直接复制到您的应用程序中。为此,请将 LVL 的 library/src/com 目录复制(或导入)到应用程序的 src/ 目录中。

我已经这样做了,但是导入:

import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;

失败.. 在google上搜索我注意到我需要修改我的项目的build.grade文件,但我找不到具体的解决方案。

如何在我的 android studio 项目中引用 LVL? 有教程或者例子吗?

谢谢 洛伦佐

【问题讨论】:

【参考方案1】:
    在 Android Studio 中,Tools-Android-SDK Manager 在 SDK 管理器的 extras 部分中,选择 Google Play Licensing Library 返回 Android Studio,选择 File-New-Import Module ADK Manager 会将下载的文件放在您的 SDK 目录下,在我的情况下为 Desktop/android-sdk-macosx/extras/google/play_licensing/library 选择将此目录作为模块导入,并为其命名。我用'lvl' 可以选择更改 lvl 模块的 build.gradle 中的 targetSdkVersion 以匹配您的项目 targetSdkVersion。 然后在您的项目 build.gradle 中,在 dependencies 部分中添加行 compile project(':lvl')。 重新同步 Gradle,一切都应该正确编译。

【讨论】:

另外,您可能希望在库的 gradle 脚本中更改 targetSdkVersion,使其与您为应用程序定位的任何版本匹配。 @NickFortescue AIDL 文件呢? android dev doc dint say step no。 7. 谢谢尼克! 您也可以将 AIDL 文件复制到 googlelicenselibrary\src\main\aidl\com\android\vending\licensing【参考方案2】:

我终于找到了解决方案! 您必须将library/src/com 目录放在youroject/scr/main/java/com 中,然后点击“Sync project with Gradle files”按钮。

【讨论】:

这对我也有用。官方 Android 开发人员文本:“将 LVL 的 library/src/com 目录复制(或导入)到应用程序的 src/ 目录中。”一点都不清楚! 我把这个方法和下面的方法结合起来,终于可以让它识别库了。也许我们应该为 Google 文档团队启动一个启动器,这样他们就可以聘请一名翻译。大声笑谢谢大家。 如果你为23 API编译,你必须在android配置中包含useLibrary 'org.apache.http.legacy':developer.android.com/about/versions/marshmallow/…【参考方案3】:

第6步放在 在project(":android")dependencies 部分内。

【讨论】:

谢谢,已纳入我上面的回答中。 这不是答案,应该作为评论添加。 我没有足够的代表发表评论。【参考方案4】:

将 LVL 源代码复制到您的应用程序。 作为将 LVL 添加为库项目的替代方法,您可以将库源直接复制到您的应用程序中。为此,请将 LVL 的 library/src/com 目录复制(或导入)到应用程序的 src/ 目录中。 访问:http://developer.android.com/google/play/licensing/setting-up.html

【讨论】:

以上是关于在 Android Studio 上设置许可验证库的主要内容,如果未能解决你的问题,请参考以下文章

Marshmallow 及以上版本的许可证验证库

在android studio上设置bitnami Parse服务器的电子邮件验证

Android Studio App未经许可或按钮发送图像

Android studio 2.1 集成第三方短信验证类库

在android studio上运行应用程序的sdk错误

接受许可时出错 - Android Studio