お世話になります。
###前提・実現したいこと
https://github.com/nobuoka/android-GoogleDriveSample
にあるサンプルを、Android studioで開き、リリースビルドでAPKを作り、これを実機で動作させ、google driveへのセーブ、ロードを正常に行うことを目標にします。そのために、下記エラーを解決する必要があります。どうすれば、解決するでしょうか。
###発生している問題・エラーメッセージ
まず、Build->generate signed apkにて、apkとjksファイルを作り、作ったjksファイルのSHA-1をkeytoolで呼び出し、これをGoogle APIの署名証明書フィンガープリントへ登録しました。
また、同じページにあるパッケージ名にinfo.vividcode.android.app.googledrivesampleを登録し、保存しました。
最後に、上記jksファイルの署名でアプリをリリースビルド、実機へインストール、起動し、実機で使用するアカウントを選択後、出現するテキストボックスに文字列を入れ、セーブボタンを押したところ、アプリが落ち、下記エラーが出ました。
12-19 20:42:35.779 14028-14075/info.vividcode.android.app.googledrivesample E/AndroidRuntime: FATAL EXCEPTION: Thread-5 Process: info.vividcode.android.app.googledrivesample, PID: 14028 java.lang.IllegalArgumentException: the name must not be empty: null at android.accounts.Account.<init>(Account.java:48) at com.google.android.gms.auth.zze.getToken(Unknown Source) at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:269) at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:294) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) at info.vividcode.android.app.googledrivesample.MainActivity$3.run(MainActivity.java:96) at java.lang.Thread.run(Thread.java:776)
###該当のソースコード
private void saveTextToDrive() { final String inputText = ((EditText)findViewById(R.id.editText)).getText().toString(); Thread t = new Thread(new Runnable() { @Override public void run() { try { // 指定のタイトルのファイルの ID を取得 String fileIdOrNull = null; FileList list = service.files().list().execute();//←ここでエラー for (File f : list.getFiles()) { if (FILE_TITLE.equals(f.getName())) { fileIdOrNull = f.getId(); } } File body = new File(); body.setName(FILE_TITLE);//fileContent.getName()); body.setMimeType("text/plain"); ByteArrayContent content = new ByteArrayContent("text/plain", inputText.getBytes(Charset.forName("UTF-8"))); if (fileIdOrNull == null) { service.files().create(body, content).execute(); showToast("insert!"); } else { service.files().update(fileIdOrNull, body, content).execute(); showToast("update!"); } // TODO 失敗時の処理? } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { showToast("error occur..."); e.printStackTrace(); } } }); t.start(); }
###試したこと
BuildToolsのバージョンを25.0.2以上をアンインストールし、
リビルドしましたが、結果は変わりません。
###補足情報(言語/FW/ツール等のバージョンなど)
Android Studio 3.0.1使用
appのbuild gradleは、下記の通りです
apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion '26.0.2' defaultConfig { applicationId "info.vividcode.android.app.googledrivesample" minSdkVersion 14 targetSdkVersion 25 } } configurations { // These modules are included in the dependencies of google-http-client, but not needed on Android. // See : https://developers.google.com/api-client-library/java/google-http-java-client/setup#google-http-client compile.exclude group: 'xpp3', module: 'xpp3' compile.exclude group: 'org.apache.httpcomponents', module: 'httpclient' } dependencies { // com.google.android.gms.common.AccountPicker とかで必要 compile 'com.google.android.gms:play-services-auth:10.2.4' // Drive API Client Library for Java // See : https://developers.google.com/api-client-library/java/apis/drive/v3 //compile 'com.google.android.gms:play-services-drive:11.6.0' compile 'com.google.apis:google-api-services-drive:v3-rev71-1.22.0' compile 'com.google.api-client:google-api-client-android:1.22.0' compile 'com.google.http-client:google-http-client-gson:1.22.0' }
宜しくお願い申し上げます。
あなたの回答
tips
プレビュー