There is a block code in build.gradle
file:
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")
I clone dev version from github, and when I open the sampleapp in Android studio, gradle building failded because of missing sampleapp.properties
file.
I already registered in Dailymotion
and created a apiKey for my application.
Now my question is how to generate a sampleapp.properties
file so that gradle building would be successful?
Thank you.
Use project.rootProject
if you are reading the properties file in a sub-project build.gradle
:
Properties props = new Properties()
props.load(project.rootProject.file('sampleapp.properties').newDataInputStream())
// your code goes here
Project structure
.
├── app
│ ├── build.gradle <-- You are reading the sampleapp.properties in this gradle build file
│ └── src
├── build.gradle
├── gradle
├── gradlew
├── settings.gradle
└── sampleapp.properties
UPDATE
Your sample.properties
file should look like shown below, just with your own values:
apiKey="yourKey"
apiSecret="yourSecret"
defaultLogin="yourLogin"
defaultPassword="yourPassword"