Setup
Build status
Setup
// Core module
implementation 'com.github.SanjayDevTech.pexels-android:core:<version>' //(1)
// Paging3 module (optional)
implementation 'com.github.SanjayDevTech.pexels-android:paging3:<version>' //(2)
- In the place of <version> you can replace any release tag Eg: 0.0.1
- In the place of <version> you can replace any release tag Eg: 0.0.1
API Key
Pexels service needs an API Key to work. Get an API key from their official website Pexels
Pexels client
Use Pexels
class to get a PexelsClient
.
JVM compatibility
It uses Java 17 as source and target compile versions. It requires the projects needs to be Java 17.
BuildConfig (Optional)
The API Keys can be extracted from public git repo, if it is used in code directly. I suggest to create secrets file and integrating into your projects.
Secrets file
Create a secrets.properties
file in root of the project. Make sure you added the secrets.properties
entry in .gitignore
, so that it won't get committed to git repository.
Paste the api key in secrets.properties
file as:
Extract key
Define the below function getApiKey()
in app/build.gradle
file.
static def getApiKey(){
def props = new Properties()
try {
props.load(new FileInputStream(new File('secrets.properties')))
return props['PEXELS_API_KEY']
} catch(ignored) {
return "\"\""
}
}
And add the API Key in the Build configuration
android {
//...
buildTypes {
debug {
// for debug
buildConfigField "String", "API_KEY", getApiKey() // This one is newly added
}
release {
// for release
buildConfigField "String", "API_KEY", getApiKey() // This one is newly added
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
Access from code
Consume the API Key using the BuildConfig
class. This class will be generated after every successful gradle build.
Demo project
I have created a demo project to demonstrate multiple ways to consume the Pexels Android Library. The sample app has been created as a sample
module in the Pexels Android Library repository itself.
Even though the sample is fully integrated, it will not contain any API Keys for the project. Follow the above BuildConfig method to add the API key.