“Minimal” source files to create Android app using Eclipse + ADT

前端 未结 3 1332
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-02 13:48

I am trying to understand the anatomy of a MINIMAL Android application, using Eclipse + ADT (Android Development Toolkit).

Please can you advise what is the MINIMAL

相关标签:
3条回答
  • 2021-01-02 13:55

    A minimal build.xml which can build and install dtmilano's code:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="MyName" default="help">
        <property environment="env" />
        <condition property="sdk.dir" value="${env.ANDROID_HOME}">
            <isset property="env.ANDROID_HOME" />
        </condition>
        <loadproperties srcFile="project.properties" />
        <import file="${sdk.dir}/tools/ant/build.xml" />
    </project>
    

    then:

    ant clean
    ant debug
    ant install
    

    Tested on Android 23, Ubuntu 15.10. Just make sure that adb install works before running this.

    On a repo to make getting the code easier.

    0 讨论(0)
  • 2021-01-02 14:00

    Strictly speaking the minimal project that displays Hello World is

    .
    ├── AndroidManifest.xml
    ├── res
    └── src
        └── com
            └── example
                └── minimal
                    └── Minimal.java
    

    Minimal.java

    package com.example.minimal;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class Minimal extends Activity {
    
        /* (non-Javadoc)
         * @see android.app.Activity#onCreate(android.os.Bundle)
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final TextView tv = new TextView(this);
            tv.setText("Hello World!");
            setContentView(tv);
        }
    
    }
    

    AndroidManifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.minimal"
        android:versionCode="1"
        android:versionName="1.0">
    
        <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />
    
        <application android:label="Minimal">
            <activity android:name="Minimal">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                </intent-filter>
            </activity>
    
        </application>
    
    </manifest>
    
    0 讨论(0)
  • 2021-01-02 14:00

    You can actually get away with just a single MyActivity.java and the manifest file, if you inflate the layout programatically. Later Eclipse Tools will create many more files (in ..drawables, layout, menu, values) by default. You can however delete them all if you make sure that the manifest doesn't refer to any icons or strings. I guess it's not seen as good practice, but it can be done.

    0 讨论(0)
提交回复
热议问题