1. ホーム
  2. Android開発

Android Studio Tips

2022-02-27 22:02:24

正直、このツールから始めるのは本当に嫌ですね、何しろ大陸が壁になっているので、いろいろと使い勝手が悪いですから。

1.インストールするとき(セットアップウィザード - コンポーネントのダウンロード)これはダウンロードに長い時間がかかるか、あるいはダウンロードすることはできません(PS:この選択とダウンロード2.25Gコンポーネントは、スタジオでのバグである、誰かがコメントで思い出した、この学生のおかげです。ネットワーク速度は、このステップをスキップしたいことができない場合は、idea.propertiesのbinディレクトリに行を追加することができます:行にdisable.android.first.run=true、Macプラットフォームを右クリックしインストールパッケージ->は、binディレクトリを見つけてパッケージ内容を表示します)。

<スパン 2. 新しいプロジェクトが無事作成されると、Gradleがダウンロードされますが、この作業は壁を登らずにダウンロードすることも可能なようですが、特にアクセスが遅いので、壁を登ってダウンロードすることをお勧めします。では、ダウンロードされたGradleはどこに行くのでしょうか?  Open C:\UsersAdministrator.gradle↵wrapper↵dists↵gradle-1.10-all\d90a2yjknzzhpcfgm937zpcte You will see the required version of gradle For example, mine is gradle-1.10.1. 10 I will go to Baidu to search for this download After downloading it, copy gradle-1.10-all.zip to this directory (C:\UsersAdministrator╱ gradle wrapper╱distsgradle-1.10-all╱d90a2yjknzzhpcfgm937zpcte).をダウンロードし、このディレクトリにコピーする。

Note: もし、ビルド中のプロジェクトをインポートする場合、プロジェクトのGradleディレクトリにあるgradle-wrapper.propertiesファイルの配布URLを変更し、最後にダウンロードしたバージョンのgradleに変更します。例えば私はすでに gradle-2.2.1-all.zip を持っていますが gradle-2.4-all.zip を持っていないので distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip に変更します。

プロジェクトをインポートした後、Android Studioをダウンロードしたら、タスクを終了して、プロジェクトのルートにあるbuild.gradleを修正します。
現在のバージョンに変更する

 依存関係 <未定義
        クラスパス 'com.android.tools.build:gradle:1.2.2' を指定します。

        // 注:アプリケーションの依存関係はここに置かないでください。
        // 個々のモジュールの build.gradle ファイルに記述します。
    }

3. build.gradleの設定について。

   メインプロジェクト アプリ :

    適用 プラグイン : com.android.application' は、このプロジェクトがメインプロジェクトとして宣言されていることを意味します。

<スパン

 依存関係 { <未定義

fileTreeをコンパイルする( ディレ : 'libs' , インクルード : [ '*.jar' ]) デフォルトでは、あまり説明は必要ありません

コンパイルプロジェクト( ':StudioKlowerBase' )} メインプロジェクトが依存するLibraryを宣言し、Libraryと同じ名前であることを確認します。

buildTypes {
    release {
        minifyEnabled true (means that when the package is signed, it is a full package and obfuscated code will be executed) 

       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

      Define the code obfuscation file Note: proguard-rules.pro should be placed in the main project's directory

    }
}

The full code is as follows.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "com.klowerbase.test"
        minSdkVersion 11
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile project(':StudioKlowerBase')
}




Configuration of the --Library project

apply plugin: 'android-library' defined as Library

dependencies {
    classpath 'com.android.tools.build:gradle:1.2.2' defines the version of gradle to be compiled

 }

The full code is as follows.

buildscript {
    repositories {
        mavenCentral()
    mavenCentral() }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.2'
    }
}
apply plugin: 'android-library'

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of their default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}






The configuration of the project The code is as follows

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Solve Task '' not found in root project '***'.
Method 1: Delete the <component name="FacetManager"> in the .iml ... </component>
Method 2: Delete the .iml and .idea folders and re-import the program
After experiments: the second method works
Since I used gradle-2.2.1, the project structure has changed a bit, as shown in the following screenshot.
<img src="https://img-blog.csdn.net/20150720130051120?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/ 400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />




Finally, some common shortcuts are included.

The full code is as follows.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "com.klowerbase.test"
        minSdkVersion 11
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile project(':StudioKlowerBase')
}



Configuration of the --Library project

apply plugin: 'android-library' defined as Library

dependencies {
    classpath 'com.android.tools.build:gradle:1.2.2' defines the version of gradle to be compiled

 }

The full code is as follows.

buildscript {
    repositories {
        mavenCentral()
    mavenCentral() }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.2'
    }
}
apply plugin: 'android-library'

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of their default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}




The configuration of the project The code is as follows
// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}



Solve Task '' not found in root project '***'.
Method 1: Delete the <component name="FacetManager"> in the .iml ... </component>
Method 2: Delete the .iml and .idea folders and re-import the program
After experiments: the second method works
Since I used gradle-2.2.1, the project structure has changed a bit, as shown in the following screenshot.

<img src="https://img-blog.csdn.net/20150720130051120?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/ 400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />


Finally, some common shortcuts are included.

Ctrl+Alt+L フォーマットコード

Ctrl+Alt+space コードヒント

Ctrl+Alt+O インポートされたクラスとパッケージの最適化

Alt+Insert コードを生成する(例:get、setメソッド、コンストラクターなど)

Ctrl+Shift+Space のオートコンプリートコード

Ctrl+Space コードヒント

Ctrl+R 置換

Ctrl+Y 行の削除(Ctrl+Xは行の削除ではなく、切り取りです。チェックをはずすと、その行が落ちそうなときにカットされます) Ctrl+D 行をコピーする Ctrl+/ または Ctrl+Shift+/ 注釈 (// または /*... */)