title: InvalidArgumentException JKS not found sheets API
body: <p>I am working on an android app that needs to interact with drive/spreadsheets. I was using the google drive for android API, but not only was it way too convoluted to figure out, it never worked right. So I switched to the REST API. I tested the app in plain java before trying to add it to android. Worked exactly as expected.
  When migrating it to android I am always greeted with the lovely </p>
  
  <p>I have tried signing it with debug.keystore and I have tried making my own keystore and generating a signed APK with both. Nothing seems to work.</p>
  
  <p>The answer I derived: <a href="https://stackoverflow.com/questions/51829976/append-to-google-drive-file-wihout-user-selection?noredirect=1#comment90636368_51829976">Append to google drive file wihout user selection</a></p>
  
  <p>I also get this error if I remove <code>packagingOptions {exclude 'META-INF/DEPENDENCIES'}</code></p>
  
  <p>from build.gradle, which I suspect might be the reason it can't find a JKS?</p>
  
  <pre><code>org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
      at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
      at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
      at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
      at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
      at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
      at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
      at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
      at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
      at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
      at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
      at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
      at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
      at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
      at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
      at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
      at com.android.builder.merge.StreamMergeAlgorithms.lambda$acceptOnlyOne$2(StreamMergeAlgorithms.java:75)
      at com.android.builder.merge.StreamMergeAlgorithms.lambda$select$3(StreamMergeAlgorithms.java:100)
      at com.android.builder.merge.IncrementalFileMergerOutputs$1.create(IncrementalFileMergerOutputs.java:86)
      at com.android.builder.merge.DelegateIncrementalFileMergerOutput.create(DelegateIncrementalFileMergerOutput.java:61)
      at com.android.build.gradle.internal.transforms.MergeJavaResourcesTransform$1.create(MergeJavaResourcesTransform.java:379)
      at com.android.builder.merge.IncrementalFileMerger.updateChangedFile(IncrementalFileMerger.java:221)
      at com.android.builder.merge.IncrementalFileMerger.mergeChangedInputs(IncrementalFileMerger.java:190)
      at com.android.builder.merge.IncrementalFileMerger.merge(IncrementalFileMerger.java:77)
      at com.android.build.gradle.internal.transforms.MergeJavaResourcesTransform.transform(MergeJavaResourcesTransform.java:411)
      at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221)
      at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217)
      at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
      at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
      at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
      at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
      at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
      ... 32 more
  
  
  
  08-15 17:57:58.516 15479-15479/io.valhala.tigerlearningcommons I/System.out: Before the THING BEGINS
      The thing BEGINS:
  08-15 17:57:58.518 15479-15479/io.valhala.tigerlearningcommons W/System.err: java.security.KeyStoreException: JKS not found
          at java.security.KeyStore.getInstance(KeyStore.java:890)
          at com.google.api.client.util.SecurityUtils.getJavaKeyStore(SecurityUtils.java:53)
  08-15 17:57:58.519 15479-15479/io.valhala.tigerlearningcommons W/System.err:     at com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:74)
          at com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55)
          at io.valhala.tigerlearningcommons.MainActivity.theThing(MainActivity.java:100)
          at io.valhala.tigerlearningcommons.MainActivity.onCreate(MainActivity.java:92)
          at android.app.Activity.performCreate(Activity.java:7009)
  08-15 17:57:58.520 15479-15479/io.valhala.tigerlearningcommons W/System.err:     at android.app.Activity.performCreate(Activity.java:7000)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
  08-15 17:57:58.521 15479-15479/io.valhala.tigerlearningcommons W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
          at android.app.ActivityThread.-wrap11(Unknown Source:0)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:164)
          at android.app.ActivityThread.main(ActivityThread.java:6494)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  08-15 17:57:58.522 15479-15479/io.valhala.tigerlearningcommons W/System.err: Caused by: java.security.NoSuchAlgorithmException: JKS KeyStore not available
          at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
          at java.security.Security.getImpl(Security.java:627)
          at java.security.KeyStore.getInstance(KeyStore.java:887)
          ... 18 more
  </code></pre>
  
  <p>This is a debug app, I am not even trying to build a release. It worked UNTIL I changed the code from GDAA to sheets v4 API. According to the documentation, it says the java quickstarts will work under android but not recommended (well the gdaa doesnt work so I have to use google rest apis)</p>
  
  <p><a href="https://stackoverflow.com/questions/50513348/jks-not-found-when-trying-googlenewhttptransport">JKS not found when trying GoogleNewHTTPTransport</a> - This author of this thread is experiencing the EXACT same issue, but with no answer.</p>
  
  <p><a href="https://stackoverflow.com/questions/18862779/storageserviceaccountsample-application-reports-keystore-jks-implementation-not">StorageServiceAccountSample application reports &quot;KeyStore JKS implementation not found&quot;</a> This author is experiencing the same issue, but it is very old, from 2013. I have tried the answer posted in 2016 to no success.</p>
  
  <p>Where does this keystore come from? Why am I missing it? I already enabled the sheets API, got my debug.keystore SHA-1, enabled it in the google api and added my credentials.json (I am assuming it's the same as in java?)
  Again, before I switched APIs, it was never giving me a JKS error.</p>
  
  <pre><code>private static final String APPLICATION_NAME = "TLC Sheets Debug";
  private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
  private static final String TOKENS_DIRECTORY_PATH = "tokens";
  private static final List&lt;String&gt; SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS);
  private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
  
  private void theThing() {
          System.out.println("Before the THING BEGINS");
          try {
              System.out.println("The thing BEGINS:");
              final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
              //final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
              final String spreadsheetId = "super_secret_id";
              Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
                      .setApplicationName(APPLICATION_NAME)
                      .build();
              ValueRange append = new ValueRange().setValues(Arrays.asList(Arrays.asList("theID", "theReason", "theTime")));
              AppendValuesResponse aResult = service.spreadsheets().values().append(spreadsheetId, "A1", append)
                      .setValueInputOption("USER_ENTERED").setInsertDataOption("INSERT_ROWS").setIncludeValuesInResponse(true).execute();
              System.out.println("The thing ENDS");
          }
          catch (IOException e) {e.printStackTrace();}
          catch (GeneralSecurityException g) {g.printStackTrace();}
      }
  
  
  
      private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
          // Load client secrets.
          InputStream in = MainActivity.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
          GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
  
          // Build flow and trigger user authorization request.
          GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                  HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                  .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
                  .setAccessType("offline")
                  .build();
          return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
      }
  </code></pre>
  
  <p>according to <a href="https://developers.google.com/api-client-library/java/google-http-java-client/reference/1.20.0/com/google/api/client/http/javanet/NetHttpTransport.Builder" rel="noreferrer">https://developers.google.com/api-client-library/java/google-http-java-client/reference/1.20.0/com/google/api/client/http/javanet/NetHttpTransport.Builder</a> the keystore needs to be loaded as an object first? Is this right, does it go in my resources folder? 
  Do I load debug.keystore, new.jks or google.jks?
  (new.jks was something I threw in there out of frustration - made a new keystore.), Am I correct in thinking that it is looking for ~/.android/debug.keystore?</p>
  
  <p><strong>build.gradle</strong></p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 28
      defaultConfig {
          applicationId "io.valhala.tigerlearningcommons"
          minSdkVersion 27
          targetSdkVersion 28
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
  
      packagingOptions {
          exclude 'META-INF/DEPENDENCIES'
      }
  
  //    buildTypes {
  //        release {
  //            minifyEnabled false
  //            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  //        }
  //    }
      buildToolsVersion '28.0.1'
  
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
      }
  
  //    signingConfigs {
  //        release {
  //            keyAlias 'androiddebugkey'
  //            keyPassword 'android'
  //            storeFile file('C:\\users\\user\\.android\\debug.keystore')
  //            storePassword 'android'
  //        }
  //        debug {
  //            keyAlias 'androiddebugkey'
  //            keyPassword 'android'
  //            storeFile file('C:\\users\\user\\.android\\debug.keystore')
  //            storePassword 'android'
  //        }
  //    }
  }
  repositories {
      mavenCentral()
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
      implementation 'com.android.support.constraint:constraint-layout:1.1.2'
      implementation 'com.google.api-client:google-api-client:1.23.0'
      implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
      implementation 'com.google.apis:google-api-services-drive:v3-rev110-1.23.0'
      implementation 'com.google.apis:google-api-services-sheets:v4-rev536-1.24.1'
      implementation 'com.google.android.gms:play-services-auth:15.0.1'
  }
  </code></pre>
  
  <p>I dug around the APK:</p>
  
  <p><a href="https://i.stack.imgur.com/LDTzu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LDTzu.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/vjj9Z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vjj9Z.png" alt="enter image description here"></a></p>
  
  <p>Thanks.</p>