[안드로이드] gradle 오프라인 빌드 환경 구축

2022. 4. 25. 15:30모바일프로그래밍

728x90

프로그램을 개발 한다 라는 것에는 많은 것들이 내포되어 있습니다.

소스 코드를 작성하기만 하면 끝이 나는 것이 아니라 컴파일하고, 빌드 한 다음 원 하는 곳에 옮겨 놓아야 합니다.

 

소스 코드를 작성 한다는 것에도 또 많은 의미들이 들어 있습니다.

소스를 어떻게 디자인 해야 할 것인지, 디자인 한 소스가 실제 환경에서는 제대로 동작을 하는 지 내가 작성한 코드의 구동 환경은 어디이며, 빌드 되고 난 다음에 어디에 넣어줘야 하는 지 (서버, 클라이언트, 모바일, 임베디드 ...) 보안에 문제를 일으키지는 않을 지 아니면 시스템에 영향을 주지는 않을 지 등등등...

 

오늘은 안드로이드 프로그램을 하다가 보니, 이클립스 환경을 결국에는 안드로이드스튜디오 환경으로 옮겨야 하는 상황이 되었습니다. 외로이 - 물론 제 생각입니다만 - 구글의 뜻을 거슬러 가면서 이클립스의 길을 굿굿하게 진행을 하고 싶지는... 않아서 말입니다.

 

개발/빌드 환경은 어찌어찌 구성 되고 나면, 이제 이 코드가 실행파일 혹은 라이브러리가 되어 실제 배치 되어야 할 곳으로 옮겨야 됩니다. 이런 생각을 넓혀가다보면,

개발 하는 것과 실제 구동하게 될 곳 즉, 배치와 개발은 따로 분리 되어야 되는 것이 맞다는 생각에 소스 코드를 개발 하는 곳과 그 소스 코드를 빌드 하는 곳을 따로 두고 관리 하기 시작 했습니다.

 

이제 문제는 소스코드를 빌드 해서 배치 하는 곳은 개발 환경을 열어서 작업 하지 않고 그냥 빌드만 하는 곳이라고 저는 정의 했다는 것이죠. 내부적으로 gradle 를 사용해서 안드로이드 소스 코드를 apk 로 빌드 할 수 있기 때문에 별 어려움이 없을 것이라고 생각 했었다는 것이죠.

 

여기서 전통적인 개발자들의 공통적 행동 방식인 (개) 삽질이 시작되는 서막이 되기 시작 했습니다.

왜냐하면, 빌드를 하려는 곳이 거의 오프라인 상황이라 뭔가가 잘 맞질 않았다는 것이죠

 

스택오버플로우의 내용을 찾아보니 다음과 같이 하라고 되어 있었습니다.

 

 

Gradle build offline ( Build fast from cache or local repo) (Android Studio v3.0+)

오프라인 환경설정의 종속성(gradle + maven) Important Note: The library or android gradle plugin v...

blog.naver.com

하지만 여전히 빌드가 실패 한 관계로 삽질이 진행 되었습니다.

 

첫번째로, 개발 프로젝트를 안드로이드 스튜디오에서 열어서 나의 프로젝트를 빌드 하여 줍니다. 

그런 다음 다음 폴더 두개를 묶어서 배치를 위한 컴퓨터의 동일 위치로 복사 저장 합니다.

기존에 폴더가 존재 했다면, 나의 경우에는 모두 삭제 해 주었습니다.

 

두번째로, 내 안드로이드 프로젝트를 빌드하기 위한 해당 폴더 내에 종속성들이 빠져 있는 것이 있었습니다.

그래서, 위 헬로 월드 프로젝트를 하나 구해서 종속성 라이브러리들을 다 구성 하고 난 다음 해당 라이브러리를 위에 있는 .android 폴더에 옮겨 주었습니다.

내가 사용한 pom.xml 파일은 다음과 같이 구성 하였습니다.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.coveros.demo</groupId>
  <artifactId>helloworld</artifactId>
  <version>1.1</version>
  <packaging>jar</packaging>

  <name>Hello World</name>
  <description>The most basic of Java programs.</description>
  <url>https://www.coveros.com/</url>
  <inceptionYear>2018</inceptionYear>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <jdk.version>1.8</jdk.version>

    <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
  </properties>
  <dependencies>
	<!-- https://mvnrepository.com/artifact/com.android.tools.build/gradle -->
	<dependency>
		<groupId>com.android.tools.build</groupId>
		<artifactId>gradle</artifactId>
		<version>3.5.3</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8 -->
	<dependency>
		<groupId>org.jetbrains.kotlin</groupId>
		<artifactId>kotlin-stdlib-jdk8</artifactId>
		<version>1.3.21</version>
	</dependency>
	
	<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
	<dependency>
		<groupId>com.google.guava</groupId>
		<artifactId>guava</artifactId>
		<version>26.0-jre</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-reflect -->
	<dependency>
		<groupId>org.jetbrains.kotlin</groupId>
		<artifactId>kotlin-reflect</artifactId>
		<version>1.3.21</version>
		<scope>runtime</scope>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-core -->
	<dependency>
		<groupId>org.glassfish.jaxb</groupId>
		<artifactId>jaxb-core</artifactId>
		<version>2.2.11</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.jvnet.staxex/stax-ex -->
	<dependency>
		<groupId>org.jvnet.staxex</groupId>
		<artifactId>stax-ex</artifactId>
		<version>1.7.7</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.sun.xml.fastinfoset/FastInfoset -->
	<dependency>
		<groupId>com.sun.xml.fastinfoset</groupId>
		<artifactId>FastInfoset</artifactId>
		<version>1.2.13</version>
	</dependency>

	<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
	<dependency>
		<groupId>javax.xml.bind</groupId>
		<artifactId>jaxb-api</artifactId>
		<version>2.3.0</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/txw2 -->
	<dependency>
		<groupId>org.glassfish.jaxb</groupId>
		<artifactId>txw2</artifactId>
		<version>2.2.11</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.sun.istack/istack-commons-runtime -->
	<dependency>
		<groupId>com.sun.istack</groupId>
		<artifactId>istack-commons-runtime</artifactId>
		<version>2.21</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
	<dependency>
		<groupId>javax.xml.bind</groupId>
		<artifactId>jaxb-api</artifactId>
		<version>2.2.12-b140109.1041</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
	<dependency>
		<groupId>com.google.code.gson</groupId>
		<artifactId>gson</artifactId>
		<version>2.8.0</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/com.google.errorprone/error_prone_annotations -->
	<dependency>
		<groupId>com.google.errorprone</groupId>
		<artifactId>error_prone_annotations</artifactId>
		<version>2.2.0</version>
	</dependency>

	
  </dependencies>
  <!--
	<repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://maven-central.storage.googleapis.com/maven2/</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://maven-central.storage.googleapis.com/maven2/</url>
    </pluginRepository>
  </pluginRepositories>
-->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven.compiler.plugin.version}</version>
        <configuration>
          <source>${jdk.version}</source>
          <target>${jdk.version}</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

settings.xml 파일의 구성은 다음과 같습니다.

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<localRepository>D:/DEV/tmp/repos</localRepository>
	<interactiveMode>true</interactiveMode>
  <offline>false</offline>
 
  <pluginGroups>   </pluginGroups>

  <proxies>   </proxies>

  <servers>  </servers>

  <mirrors>  </mirrors>

  <profiles>
	<profile>
		<id>myprofile</id>
		<repositories>
			<repository>
				<releases>
					<enabled>true</enabled>
				</releases>
				<id>central</id>
				<url>https://repo.maven.apache.org/maven2</url>
			</repository>
			
			<repository>
				<id>central</id>
				<url>https://dl.google.com/dl/android/maven2/</url>
			</repository>
			
			<repository>
				<id>jcenter</id>
				<name>jcenter</name>
				<url>https://jcenter.bintray.com</url>
			</repository>
			
		</repositories>
		
      <pluginRepositories>
        <pluginRepository>
          <releases>
            <enabled>true</enabled>
          </releases>
          <id>central</id>
          <url>https://repo.maven.apache.org/maven2</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

   <activeProfiles>
    <activeProfile>myprofile</activeProfile>
  </activeProfiles>
</settings>

세번째, 메인 build.gradle 파일 내의 내용 중 repositories 부분의 주석처리를 했다면 다시 풀어 주었습니다.

 

마지막으로 빌드를 하기 전에 다음과 같은 환경 설정을 해 주었습니다.

명령은 다음과 같이 하면 됩니다.

gradle assemble
혹은 디버깅 용도로
gradle assembleDebug

이상.

728x90