android-studiohttpscertificate

Issue with Accessing Offline Repository with https in Android Studio


I'm working on an Android app in Android Studio 2024.2.1 Patch 2 on Ubuntu 24.04 (on a VM) in an offline environment. To handle dependencies, I’ve set up an offline repository hosted on a networked computer with Apache 2. The repository is configured to use HTTP (port 80) and HTTPS (port 443), and I’m using a self-signed certificate for the HTTPS connection.

On my computer with Android Studio I set the repository URI (for plugins and dependencies) in the settings.gradle.kts file to

maven {
   url = uri("https://maven.google.com")
}

The /etc/hosts file redirects maven.google.com to the repository computer.

On a gradle sync in Android Studio I get the simple error, that the dependencies cannot be found (com.android.application, 8.7.2). I added the necessary certificate to the cacerts file in my home directory (~/.config/Google/AndroidStudio2024.2/ssl/cacerts) and I called "update-ca-certificates".

When I set the URI to http://maven.google.com (port 80) and add the flag to allow insecure protocols, Android Studio finds and downloads the dependencies as expected.

Firefox can access the https repository though (after accepting the self-signed-certificate-warning) and download the files.

Why not Android Studio? What am I missing out?


Solution

  • I had to adjust the cacerts file of the JDK used by Gradle. Which JDK is used by Gradle can be checked in Android Studio under File/Settings/Build, Execution, Deployment/Build Tools/Gradle.