App을 새로 생성해서 테스트 하려고 하니 오류가 나옵니다.

 

Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.

 

 

Gradle을 살펴보고

 

android {
   
compileSdkVersion
31
   
buildToolsVersion "31.0.0"

   
defaultConfig {
       
applicationId
"copycoding.tistory.sample"
       
minSdkVersion 16
       
targetSdkVersion 31
       
versionCode 1
       
versionName "1.0"

       
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   
}

 

설치된 SDK Tool도 살펴봐도

 

 

 

별 문제 없는것 같은데..

 

 

1. 버전 낮추기

 

다시 설치하긴 귀찮고 전체적으로 버전을 30으로 낮추어 봅니다. 

 

android {
   
compileSdkVersion
30
   
buildToolsVersion "30.0.3"

   
defaultConfig {
       
applicationId
"copycoding.tistory.sample"
       
minSdkVersion 16
       
targetSdkVersion 30
       
versionCode 1
       
versionName "1.0"

       
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.5.0'

 

 

이런.  새로운 오류가 발생 합니다.

 

 

ERROR:C:\Users\will\.gradle\caches\transforms-2\files-2.1\4eb2fc21ccc2dce4da190845bc3482ac\material-1.5.0\res\values-v31\values-v31.xml:3:5-94: AAPT: error: resource android:color/system_neutral1_1000 not found.

 

Material Component Library 버전이 업데이트 되어서 31을 사용해야 한다고 합니다.

답을 찾았네요.  material 버전을 낮추면 되는거군요.

 

android {
   
compileSdkVersion 30
   
buildToolsVersion "30.0.3"

    
defaultConfig {
       
applicationId
"copycoding.tistory.sample"
       
minSdkVersion 16
       
targetSdkVersion 30
       
versionCode 1
       
versionName "1.0"

       
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   
}

   
buildTypes {
       
release {
           
minifyEnabled
false
           
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
       
}
    }
   
compileOptions {
       
sourceCompatibility JavaVersion.
VERSION_1_8
       
targetCompatibility JavaVersion.VERSION_1_8
   
}
}



dependencies {

   
implementation 'androidx.appcompat:appcompat:1.3.1'
   
implementation 'com.google.android.material:material:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
   
testImplementation 'junit:junit:4.+'
   
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
   
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

  

material 버전을 1.5.0에서 1.2.0으로 변경 하나 잘 됩니다.  물론 1.4.0로 낮추어도 됩니다.

 

 

 

 

2. buildToolsVersion 낮추기

 

다른건 그대로 두고 buildToolsVersion만 낮추어서 해결해 봅니다.

Android Studio에서 Gradle을 열고 오른쪽 상단을 보면 Open (Ctrl+Alt+Shift+S)가 있는데

 

 

이걸 누르면 창이 하나 뜨고

 

 

여기서 Build Tools Version을 확장하여 31.0.0 대신 하나 낮은걸 선택 합니다.

  

android {
   
compileSdkVersion
31
   
buildToolsVersion '30.0.3'

   
defaultConfig {
       
applicationId
"copycoding.tistory.test"
       
minSdkVersion 16
       
targetSdkVersion 31
       
versionCode 1
        
versionName "1.0"

 

 

 

그리고 실행하면 다른 오류가 발생 합니다.

 

Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

 

 

android:exported 이게 문제라는 군요.  참조하라는 링크를 따라가보면 설명이 있습니다.

https://developer.android.com/guide/topics/manifest/activity-element#exported

 

어째든 android:exportedManifest에 추가하고 값을 넣으면 됩니다.  만일 false를 넣으면 앱이 생성은 되는데 실행하려고 하면 app is’nt installed라는 토스트만 나오니 true를 적어 줍니다.

값을 설정하는 위치는 activity에 해주어야 합니다.

  

<activity android:name=".MainActivity"
   
android:exported="true"
>
    <
intent-filter>
        <
action android:name="android.intent.action.MAIN" />

        <
category android:name="android.intent.category.LAUNCHER" />
    </
intent-filter>
</
activity>

 

이렇게 하면 앱을 잘 테스트할 수 있습니다.

 

 

이건 제가 간단한 테스트를 하려고 한것이고 실제로는 높은 버전으로 컴파일 해야 최신 핸드폰에서도 잘 돌아가는 앱을 만들 수 있겠죠.

 

- copy coding -

STS에는 WAStomcat이 포함되어 있어서 별도로 설치를 하지 않아도 되고 jar 파일을 생성하면 jar 파일내에 tomcat이 들어가기 때문에 개인지 테스트 삼하 작업 하기에는 편리한 툴 입니다.  물록 tomcat으로 서비스를 하는 회사들도 있기때문에 개발하고 바로 서비스를 할 수도 있습니다.  

작업 순서는

 

1. STS 다운로드 및 설치

2. 프로젝트 생성

3. 소스코드 개발

4. jarbuild 및 서비스

 

jar 파일을 만들기 위해 STS를 설치부터 해 봅니다.

 

https://spring.io/tools

 

사이트에 접속해서 OS에 맞는 버전을 다운로드 받습니다.

 

jar 형태의 압축파일을 풀고 contents.zip 압축파일도 풀어주면 sts-4.12.1 폴더를 얻을 수 있습니다.  압축은 zip 파일을 풀드시 일반적인 툴을 이용합니다.

 

여기서 한번더 contents를 풀면 됩니다.

 

SpringToolSuite4를 실행하고

 

작업을 진행할 폴더를 선택해주고 [Launch]를 선택하면

 

개발 툴 화면을 볼 수 있습니다.

 

한번 신규 프로젝트를 생성해 봅니다.

 

File > New > Spring Starter Project

 

Type, Packaging, Java Version, Language4개를 자신의 취향에 맞도록 수정 가능 합니다.  요즘에는 Maven 보다 Gradle을 많이 사용하니 Gradle로 설정을 해서 생성합니다.

 

간단한 확인만 하려는 것이니 [Spring Web]만 선택 합니다.

 

프로젝트가 생성이 되었고 기본적인 소스도 자동으로 만들어 집니다.

 

간단하게 사용할 것이므로 콘솔 버퍼는 나중에 변경시키기로 하고 일단 실행을 해 봅니다.

 

툴의 좌측 하단에서 demo 를 선택 하고 빨간색 네모 둘중 하나를(실행, 디버깅) 클릭하면 embeded tomcat8080으로 잘 실행 되었다고 우측에 표시 됩니다.

 

웹에서 확인해 봅니다.

 

아직 아무것도 만들지 않아서 기본 오류페이지가 잘 나오고 있습니다.  설치는 완료 되었군요.

 

API를 하나 생성 합니다.

 

실행하면

 

잘 되는군요. 이제 jar 파일을 생성해 봅니다.

 

Gradle Tasks를 열고 bootJar를 더블클릭 합니다.  빌드가 완료되면

 

build > libs 폴더에 파일이 생성 되었습니다.

 

생성된 jar 파일을 별도로 띄워 봅니다.  먼저 8080포트가 충돌나지 않도록 STS에 띄워놓은 프로젝트는 중지를 하고 CMD 창을 하나 열어서

Java로 실행을 해 봅니다.

javapath에 등록 했다면

 

java -jar demo-0.0.1-SNAPSHOT.jar

 

그렇지 않다면 java의 전체 위치를 같이 사용하여 실행 합니다.

 

D:\Java\jdk1.8.0_131\bin\java -jar demo-0.0.1-SNAPSHOT.jar

 

실행이 되었다면 웹에서 확인해 봅니다.

 

잘 나오는 군요.  실제 서버에서도 이렇게 jar를 이용해서 서비스 해도 됩니다.

jar에는 내장 톰캣이 있는데 톰캣을 제외하고 외부 톰캣이나 다른 WAS를 사용한 테스트를 하기 위해 조만간 WAR로 배포를 해봐야겠네요.

 

- copy coding -


Android 프로그램을 하면서 사용할 일은 거의 없지 찾으려면 구글링을 해야 해서 한번에 모아 놓고 참조하기 위해 정리를 해 보았습니다.

 

플랫폼 버전 별 API 레벨

 

플랫폼 버전

API 레벨

플랫폼 명

버전 코드

Android 10.0

29

Q

Q

Android 9

28

Pie

P

Android 8.1

27

Oreo

O_MR1

Android 8.0

26

Oreo

O

Android 7.1.1

Android 7.1

25

Nougat

N_MR1

Android 7.0

24

Nougat

N

Android 6.0

23

Marshmallow

M

Android 5.1

22

Lollipop

LOLLIPOP_MR1

Android 5.0

21

Lollipop

LOLLIPOP

Android 4.4W

20

KitKat Wear

KITKAT_WATCH

Android 4.4

19

KitKat

KITKAT

Android 4.3

18

Jelly Bean

JELLY_BEAN_MR2

Android 4.2

Android 4.2.2

17

Jelly Bean

JELLY_BEAN_MR1

Android 4.1

Android 4.1.1

16

Jelly Bean

JELLY_BEAN

Android 4.0.3

Android 4.0.4

15

IceCreamSandwich

ICE_CREAM_SANDWICH_MR1

Android 4.0

Android 4.0.1

Android 4.0.2

14

IceCreamSandwich

ICE_CREAM_SANDWICH

Android 3.2

13

Honeycomb

HONEYCOMB_MR2

Android 3.1.x

12

Honeycomb

HONEYCOMB_MR1

Android 3.0.x

11

Honeycomb

HONEYCOMB

Android 2.3.4

Android 2.3.3

10

Gingerbread

GINGERBREAD_MR1

Android 2.3.2

Android 2.3.1

Android 2.3

9

Gingerbread

GINGERBREAD

Android 2.2.x

8

Froyo

FROYO

Android 2.1.x

7

Eclair

ECLAIR_MR1

Android 2.0.1

6

Eclair

ECLAIR_0_1

Android 2.0

5

Eclair

ECLAIR

Android 1.6

4

Donut

DONUT

Android 1.5

3

Cupcake

CUPCAKE

Android 1.1

2

Base

BASE_1_1

Android 1.0

1

Base

BASE

 

프로그램에서 플랫폼 버전 별 작업을 해야 한다면 실제로 사용할 수 있는 값은 API 레벨과 버전 코드를 사용하여 조건문을 생성하여 사용하면 됩니다.

안드로이드 프로그램 내에서 현재 사용하는 단말기의 VersionBuild.VERSION.SDK_INT를 이용하여 구하면 되고 비교 값으로는 API 레벨을 사용 하거나 버전 코드는 Build.VERSION_CODES.[버전 코드]를 이용하여 API 레벨 상수 값을 구할 수 있습니다.


- API 레벨을 사용하는 경우


 if(Build.VERSION.SDK_INT >= 23){

    // 필요한 코딩 작업

}


- 버전 코드를 사용하는 경우


if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

    // 필요한 코딩 작업

}


 

안드로이드 단말기의 버전은 Build.VERSION.SDK_INT을 이용하여 얻을 수 있었는데 좀더 상세한 값들도 구할 수 있습니다.

  

Return Type

Code

Description

String

BASE_OS

The base OS build the product is based on.

String

CODENAME

The current development codename, or the string "REL" if this is a release build.

String

INCREMENTAL

The internal value used by the underlying source control to represent this build.

String

PREVIEW_SDK_INT

The developer preview revision of a prerelease SDK.

String

RELEASE

The user-visible version string.

String

RELEASE_OR_CODENAME

The version string we show to the user; may be RELEASE or CODENAME if not a final release build.

String

SDK

This field was deprecated in API level 15. Use SDK_INT to easily get this as an integer.

String

SDK_INT

The SDK version of the software currently running on this hardware device.

String

SECURITY_PATCH

The user-visible security patch level.

 

실제 프로그램에서 Code를 사용 하려면 Build.VERSION.[Code]와 같이 이용하면 됩니다간단하게 프로그램을 만들어서 출력을 하는 프로그램을 만들어 보면


 

public class MainActivity extends AppCompatActivity {

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
       
setContentView(R.layout.activity_main);

       
TextView textView = (TextView) findViewById(R.id.version);
       
StringBuffer sBuffer = new StringBuffer();
        if
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            sBuffer.append(
"Build.VERSION.BASE_OS = " + Build.VERSION.BASE_OS);
           
Log.v("myDevice","Build.VERSION.BASE_OS = " + Build.VERSION.BASE_OS);
       
}
        Log.v(
"myDevice","Build.VERSION.CODENAME = " + Build.VERSION.CODENAME);
       
Log.v("myDevice","Build.VERSION.INCREMENTAL = " + Build.VERSION.INCREMENTAL);
       
Log.v("myDevice","Build.VERSION.RELEASE = " + Build.VERSION.RELEASE);
       
Log.v("myDevice","Build.VERSION.SDK = " + Build.VERSION.SDK);
       
Log.v("myDevice","Build.VERSION.SDK_INT = " + Build.VERSION.SDK_INT);
       
sBuffer.append("\nBuild.VERSION.CODENAME = " + Build.VERSION.CODENAME);
       
sBuffer.append("\nBuild.VERSION.INCREMENTAL = " + Build.VERSION.INCREMENTAL);
       
sBuffer.append("\nBuild.VERSION.RELEASE = " + Build.VERSION.RELEASE);
       
sBuffer.append("\nBuild.VERSION.SDK = " + Build.VERSION.SDK);
       
sBuffer.append("\nBuild.VERSION.SDK_INT = " + Build.VERSION.SDK_INT);
        if
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            sBuffer.append(
"\nBuild.VERSION.SECURITY_PATCH = " + Build.VERSION.SECURITY_PATCH);
           
Log.v("myDevice","Build.VERSION.SECURITY_PATCH = " + Build.VERSION.SECURITY_PATCH);
       
}
        textView.setText(sBuffer)
;
   
}
}

 

이런 식으로 코드를 작성 하고 실행하면


android version


이렇게 버전에 대한 상세내역을 얻을 수 있습니다.


- copy coding -



1

+ Recent posts