0

I have read this source . But when I add a library on my android studio, I am encountering the following error.

Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'

After that I read this article and used gradle as follows.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.test.test"
        minSdkVersion 21
        targetSdkVersion 21
        versionCode 4
        versionName "1.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    android {
        configurations.all {
            resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
        }
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.google.api-client:google-api-client:1.23.0'
    compile 'com.google.android.gms:play-services-auth:11.8.0'
    compile 'com.google.android.gms:play-services-drive:11.8.0'
    compile 'com.google.android.gms:play-services-ads:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.github.bumptech.glide:glide:4.3.1'
    implementation 'com.android.volley:volley:1.0.0'
    implementation 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:cardview-v7:26.1.0'
    implementation files('libs/YouTubeAndroidPlayerApi.jar')
    compile 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
}

MainActivity.java

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestScopes(Drive.SCOPE_FILE)
            .requestScopes(Drive.SCOPE_APPFOLDER)
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

 GoogleSignInAccount lastSignedInAccount = GoogleSignIn.getLastSignedInAccount(this);
        mDriveClient = Drive.getDriveClient(this, lastSignedInAccount);
        mDriveResourceClient =
                Drive.getDriveResourceClient(this, lastSignedInAccount);
        SortOrder sortOrder = new SortOrder.Builder().addSortAscending(SortableField.TITLE).build();

        Query query = new Query.Builder()
                .addFilter(Filters.eq(SearchableField.TITLE, "test.txt"))
                .build();
        //Drive.DriveApi.fetchDriveId(mGoogleApiClient)
        Task<MetadataBuffer> queryTask = mDriveResourceClient.query(query);
        queryTask
                .addOnSuccessListener(this,
                        new OnSuccessListener<MetadataBuffer>() {
                            @Override
                            public void onSuccess(MetadataBuffer metadataBuffer) {
                                Log.d("Count file" +metadataBuffer.getCount());
                            }
                        })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {

                    }
                });

But i cannot find the GoogleAccountCredential function within my project.

Any pointers will be appreciated.

3 Answers3

0

Add " apply plugin: 'com.google.gms.google-services' " line at bottom of your build.gradle file.

Amit Jangid
  • 2,741
  • 1
  • 22
  • 28
0

Try replacing your dependency with this on.

compile 'com.google.api-client:google-api-client-android:1.20.0'

This might work but not sure.

Amit Jangid
  • 2,741
  • 1
  • 22
  • 28
0

implementation 'com.google.android.gms:play-services-drive:15.0.1'

        Query query = new Query.Builder()
            .addFilter(Filters.eq(SearchableField.TITLE, namasteId+"_database.zip"))
            .build();

    Drive.getDriveResourceClient(context, googleSignInAccount).query(query)

            .addOnSuccessListener(new OnSuccessListener<MetadataBuffer>() {
                @Override
                public void onSuccess(MetadataBuffer metadata) {

                    try{
                        Drive.getDriveResourceClient(context, googleSignInAccount);
                        DriveFile backupfolder = metadata.get(0).getDriveId().asDriveFile();
                        retrieveContents(backupfolder);
                    }catch (Exception e){
                        Toast.makeText(activity, "No Data Found", Toast.LENGTH_SHORT).show();
                        activity.finish();
                        progressDialog.cancel();
                    }
                }
            })
            // if no backup folder is found, create a new backup folder
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    createBackupFolder(context, googleSignInAccount);
                }
            });

If u need file selection activity, then u can use this commented code

  pickFile()
                            .addOnSuccessListener(activity,
                                    driveId -> retrieveContents(driveId.asDriveFile()))
                           .addOnFailureListener(activity, e -> {
                               Log.e(TAG, "No file selected", e);
                           });