How to integrate the Android Google Drive Sync library into your project
- Android SDK 26+ (Android 8.0 Oreo)
- Kotlin 1.9+
- Google Cloud Project with Drive API enabled
- OAuth 2.0 credentials configured
- Go to Google Cloud Console
- Create a new project or select an existing one
- Note your project ID
- Navigate to APIs & Services > Library
- Search for "Google Drive API"
- Click Enable
- Navigate to APIs & Services > OAuth consent screen
- Select External user type (or Internal for organization)
- Fill in required fields:
- App name
- User support email
- Developer contact information
- Add scopes:
https://www.googleapis.com/auth/drive.filehttps://www.googleapis.com/auth/drive.appdata(optional)
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Android as application type
- Enter your app's package name
- Enter your app's SHA-1 certificate fingerprint
# Debug keystore keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android # Release keystore keytool -list -v -keystore your-release-key.keystore -alias your-alias
- Download the credentials JSON file
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}
// app/build.gradle.kts
dependencies {
implementation("com.vanespark:google-drive-sync:1.0.0")
}// settings.gradle
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}
// app/build.gradle
dependencies {
implementation 'com.vanespark:google-drive-sync:1.0.0'
}@Module
@InstallIn(SingletonComponent::class)
object SyncModule {
@Provides
@Singleton
fun provideSyncConfiguration(): SyncConfiguration {
return SyncConfiguration.builder()
.appFolderName("MyApp")
.addSyncDirectory(SyncDirectory("documents"))
.conflictPolicy(ConflictPolicy.NEWER_WINS)
.networkPolicy(NetworkPolicy.UNMETERED_ONLY)
.build()
}
@Provides
@Singleton
fun provideGoogleSyncClient(
@ApplicationContext context: Context,
configuration: SyncConfiguration
): GoogleSyncClient {
return GoogleSyncClient.create(context, configuration)
}
}class MyApplication : Application() {
lateinit var syncClient: GoogleSyncClient
private set
override fun onCreate() {
super.onCreate()
val configuration = SyncConfiguration.builder()
.appFolderName("MyApp")
.build()
syncClient = GoogleSyncClient.create(this, configuration)
}
}See README.md for basic usage examples.
See CONFIGURATION.md for detailed configuration options.
See TROUBLESHOOTING.md for common issues and solutions.