我已经在Dailymotion注册并创建了apiKey,那么如何生成sampleapp.properties文件呢?

I already registered in Dailymotion and create apiKey, then how do I generate sampleapp.properties file?

build.gradle文件中有块代码:

Properties props = new Properties()
props.load(new FileInputStream("sampleapp.properties"))

buildConfigField "String", "apiKey", props.getProperty("apiKey")
buildConfigField "String", "apiSecret", props.getProperty("apiSecret")
buildConfigField "String", "defaultLogin", props.getProperty("defaultLogin")
buildConfigField "String", "defaultPassword", props.getProperty("defaultPassword")

我从 github 克隆开发版本,当我在 Android studio 中打开示例应用程序时,gradle 构建失败,因为缺少 sampleapp.properties 文件。

我已经在 Dailymotion 中注册并为我的应用程序创建了一个 apiKey。 现在我的问题是如何生成 sampleapp.properties 文件以便 gradle 构建成功?

谢谢。

如果您正在阅读 sub-project build.gradle:

中的属性文件,请使用 project.rootProject
Properties props = new Properties()
props.load(project.rootProject.file('sampleapp.properties').newDataInputStream())
// your code goes here

项目结构

.
├── app
│   ├── build.gradle <-- You are reading the sampleapp.properties in this gradle build file
│   └── src
├── build.gradle
├── gradle
├── gradlew
├── settings.gradle
└── sampleapp.properties

更新 您的 sample.properties 文件应该如下所示,只是带有您自己的值:

apiKey="yourKey"
apiSecret="yourSecret"
defaultLogin="yourLogin"
defaultPassword="yourPassword"