I'm trying to use the OneDrive SDK by following the instructions shown here. Unfortunately I can't perform a Gradle project sync when I add the dependencies shown in the SDK installation guide. I get the following error message:
ERROR: Could not find method repository() for arguments [build_xqhe0znpcz2uhmxa019kwrtr$_run_closure2@18623fec] on project ':app' of type org.gradle.api.Project.
Please can someone help me identify the problem? My build.gradle
file looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.onedrivesdkapp"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
repository {
jcenter()
}
dependency {
// Include the sdk as a dependency
compile ('com.onedrive.sdk:onedrive-sdk-android:1.3+') {
transitive = false
}
// Include the gson dependency
compile ('com.google.code.gson:gson:2.3.1')
// Include supported authentication methods for your application
compile ('com.microsoft.services.msa:msa-auth:0.8.+')
compile ('com.microsoft.aad:adal:1.1.+')
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
It seems onedrive-sdk-android library is no longer maintained because the latest commit is 2 years ago.
Problem: Your code to import dependencies is not correct, that why Gradle throws the error.
Solution: Do the following steps.
Step 1: Remove the following line from gradle file
repository {
jcenter()
}
dependency {
// Include the sdk as a dependency
compile ('com.onedrive.sdk:onedrive-sdk-android:1.3+') {
transitive = false
}
// Include the gson dependency
compile ('com.google.code.gson:gson:2.3.1')
// Include supported authentication methods for your application
compile ('com.microsoft.services.msa:msa-auth:0.8.+')
compile ('com.microsoft.aad:adal:1.1.+')
}
Step 2: Move all dependencies line to dependencies
block.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Include the sdk as a dependency
implementation ('com.onedrive.sdk:onedrive-sdk-android:1.3+') {
transitive = false
}
// Include the gson dependency
implementation ('com.google.code.gson:gson:2.3.1')
// Include supported authentication methods for your application
implementation ('com.microsoft.services.msa:msa-auth:0.8.+')
implementation ('com.microsoft.aad:adal:1.1.+')
}
Put all together, your gradle file will look like
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.onedrivesdkapp"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Include the sdk as a dependency
implementation ('com.onedrive.sdk:onedrive-sdk-android:1.3+') {
transitive = false
}
// Include the gson dependency
implementation ('com.google.code.gson:gson:2.3.1')
// Include supported authentication methods for your application
implementation ('com.microsoft.services.msa:msa-auth:0.8.+')
implementation ('com.microsoft.aad:adal:1.1.+')
}