Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build project without internet connection

Tags:

android

gradle

I have project that is required to work on in offline mode without any internet connection due to security reasons. My androidStudio defined to offline mode. When I run assemble release via Task/build/assembleRelease everything work just fine and I build my apk. But when running via command line command:

gradlew --offline assembleRelease

I get bunch of errors than no cashed version of this and that. When I fix one error and copy some files to cache then I get new error that something else missing.

So, how is assembleRelease via androidStudio works? How can I run the same command via cmd or remotely, because it seems have all the cache needed. What is the difference running assembleRelease from studio vs from cmd?

Also I know the simple solution, run it one time online and then it works. Can`t do so...

As my PC is capable of building APK overall, how can I do so without androidStudio just via cmd or remotely?

like image 461
Dim Avatar asked Jun 28 '18 07:06

Dim


People also ask

Can an app work without internet?

Native mobile apps act as the interface between the user and the users' data and require uninterrupted connectivity. Native mobile apps with offline capability stores both the mobile app's software and its data locally on the mobile device. Offline mobile apps allow the user to run the app, regardless of connectivity.

Does Gradle build require internet?

Gradle needs an internet connection to download the dependencies that you specify. Once it downloads everything, it can put them in memory so that you can work offline. To do this, you need to go to Files->Settings (For Mac: Android Studio-> Settings...). You can now build your project without internet.

Can Android Studio be used offline?

Yes, Android Studio is meant to be used offline, unless you are using git and committing all your code changes to git. One other scenario when you need the internet is when trying to use some external library/API using gradle.

Does Gradle sync require internet connection?

Gradle Sync requires a stable internet connection for downloading various versions required for the project online. Hence it is always advised to check your internet connection before syncing your project in Android Studio.


1 Answers

First of all, it really surprises me that you can build your project using Android Studio, but not by calling Gradle directly. Different Gradle versions could be one reason, but since you already use the Gradle wrapper, it is rather unlikely. Maybe Android Studio is not configured to use the wrapper.


However, I would definitively advise against copying dependencies between the Gradle caches of different systems. Instead, I would encourage you to collect the required dependencies in an offline repository, e.g. a flatDir repository:

repositories {
    flatDir name: 'offlineRepository', dirs: "C:/path/to/repository"
}

Sadly, flatDir repositories do not support transitive dependencies from descriptor files like Maven .pom files, but you can also define maven or ivy repositories for a local filesystem location:

repositories {
    maven {
        name = 'offlineRepository'
        url = uri('file:///c:/path/to/repository')
    }
}

If it should be possible to build your project from both an online and your specific offline environment, you may think about defining an initialization script on your local machine, that substitutes any defined repository with your offline repository.

like image 148
Lukas Körfer Avatar answered Sep 23 '22 05:09

Lukas Körfer