728x90

require문, include문 : 자주 사용하는 PHP 코드를 다른 파일에 모아 두고 필요할 때 파일을 읽어들여서 사용할 수 있도록 하는 명령


require "파일명";

- 만일 지정된 파일이 존재하지 않을 경우에는 php.ini에 설정된 include_path에서 파일을 찾는다.

- include_path에도 파일이 존재하지 않는다면 require문을 작성한 현재 파일이 있는 디렉토리에서 찾는다.

- 현재 디렉토리에도 없다면 오류표시하고 정지된다.



require와 include의 차이점

- require문은 오류가 발생했을 경우에 Fatal Error가 되어 정지가 되어버린다.

- require_once() : 지정한 파일을 한 번 읽어 들이면 같은 처리 중에는 다시 읽어 들일 수 없다.

- include문은 오류가 발생했을 경우에 Warning을 출력하고 처리코드를 수행한다.

- include_once() : 지정된 파일을 이미 읽어 들어 경우에는 다시 파일을 읽어 들이지 않는다.



블로그 이미지

Link2Me

,
728x90

모듈을 추가하는 것은 Contacts Demo 파일을 순수하게 Android Studio 버전에서 생성하는 과정이라고 볼 수 있다.

모듈 추가 과정을 상세하고 보고 싶다면 확인해라.


이제 build.gradle 부분이 http://link2me.tistory.com/1304 와 어떻게 다른지 살펴보자.


apply plugin: 'com.android.application'

android {
    compileSdkVersion 15
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "com.prince.contacts"
        minSdkVersion 8
        targetSdkVersion 15
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "com.tistory.link2me.contacts_demo_for_studio"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}


build.gradle 부분이 다른 걸 확인했으니 코드를 복사해서 붙여넣기 했더니 문제없이 잘 동작한다.

다만, AndroidMenifest.xml 에서 약간 수정할 부분이 좀 있었다.


첨부된 소스코드는 Android Studio 에서 완전히 작성된 코드라고 보면 된다.


Contact_Demo.zip



Eclipse 버전의 샘플 소스는 http://link2me.tistory.com/1301 에 올려져 있다.


블로그 이미지

Link2Me

,
728x90

Contacts Demo 앱을 Android Studio 용으로 변환을 시도한 결과를 적어둔다.


=== build.gradle (Module) ====

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 15
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "com.prince.contacts"
        minSdkVersion 8
        targetSdkVersion 15
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

 === build.gradle (Project) ====

 buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}


=== AndroidManifest.xml ===

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.prince.contacts"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="AddContact"
            android:label="@string/add"
            android:theme="@android:style/Theme.Dialog" >
        </activity>
        <activity
            android:name="DeleteContacts"
            android:label="@string/delete"
            android:theme="@android:style/Theme.Dialog" >
        </activity>
    </application>

</manifest>


Eclipse 에서 Android Studio 용으로 변환을 하면 주의해서 살펴볼 내용을 위 사항이라고 본다.


jave 소스코드와  Layout 파일은 build.gradle 이 달라짐에 따라서 에러,경고 등이 생길 수 있다.

높은 버전에서 문제없이 코드가 동작되도록 하는 것은 상황에 맞게 수정해야 한다.

블로그 이미지

Link2Me

,
728x90

Android Studio 3.1.4 버전에서는 아래 사항을 무시해도 된다.

이미 문제를 해결하여 반영한 거 같다.


Android Studio 3.0 으로 업그레이드/설치하고 나서 Preview Layout 이 보이지 않을 경우 설치된 Android Studio 에서 \plugins\android\lib\layoutlib\data\fonts\ 에 fonts.xml 파일을 찾아서 아래 파일을 받아서 덮어쓰기하면 된다.


fonts.xml




아래 사항은 Android Studio 2.X버전에서 Layout 미리보기를 하면 한글이 깨져보이는 증상을 해결하는 방법이다.


font.xml 파일을 EditPlus로 열어서 보면

<family lang="ko">
    <font weight="400" style="normal" index="1">NotoSansCJK-Regular.ttc</font>
</family>

라고 되어 있는 부분을 아래 그림과 같이 수정하면 된다.


NanumGothic.ttf 파일은 설치되어 있다.

Layout PreView 에 설정된 폰트 NotoSansCJK-Regular.ttc 가 MAC 용에서 인식하는 한글이라고 한다.

즉 Android Studio 개발을 MACBook 에서 개발할 것으로 보고 만들었나 보다.

윈도우 운영체제에서 인식이 잘 안되는 이유가 여기에 있었던가 보다.

실제 Macbook 을 사용하시는 분이 맥북에서는 Android Stuio 인식이 엄청 빠른데 윈도우에서는 상당히 느리다고 하더라.

폰트 변경을 해주었으면 바로 자동 인식은 안되니까 Android Stuio 를 종료했다가 재실행하면 인식이 잘 된다.




블로그 이미지

Link2Me

,