ÔÚLinuxÉÏʹÓÃVisual Studio¾ÙÐÐÒƶ¯Ó¦Óÿª·¢µÄÍƼöÉèÖÃ
ÔÚlinuxÉÏʹÓÃvisual studio¾ÙÐÐÒƶ¯Ó¦Óÿª·¢µÄÍƼöÉèÖÃ
Òƶ¯Ó¦Óÿª·¢ÔÚµ±½ñµÄÈí¼þ¿ª¿¯ÐÐÒµÖбäµÃÔ½À´Ô½Ö÷Òª¡£¶ø×÷ΪһÃû¿ª·¢Õߣ¬Ñ¡ÔñºÏÊʵĿª·¢¹¤¾ßºÍÉèÖÃÊÇÖÁ¹ØÖ÷ÒªµÄ¡£¹ØÓÚϲ»¶Ê¹ÓÃLinux²Ù×÷ϵͳµÄ¿ª·¢ÕßÀ´Ëµ£¬Visual StudioÊÇÒ»¸öÇ¿Ê¢µÄ¿ª·¢¹¤¾ß¡£±¾ÎĽ«ÏÈÈÝLinuxÉÏʹÓÃVisual Studio¾ÙÐÐÒƶ¯Ó¦Óÿª·¢µÄÍƼöÉèÖ㬲¢´øÓÐÏìÓ¦µÄ´úÂëʾÀý¡£
Ê×ÏÈ£¬È·±£ÄãµÄLinux²Ù×÷ϵͳÒѾװÖÃÁËVisual Studio Code£¬ÕâÊÇÒ»¸öÓÉ΢Èí¿ª·¢µÄÇáÁ¿¼¶µ«¹¦Ð§Ç¿Ê¢µÄIDE¡£Äã¿ÉÒÔͨ¹ý¹Ù·½ÍøÕ¾ÏÂÔز¢×°ÖÃ×îа汾µÄVisual Studio Code¡£
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÉèÖÃAndroid¿ª·¢ÇéÐΡ£Android¿ª·¢ÐèҪʹÓÃJava¿ª·¢ÓïÑÔºÍAndroid SDK¡£È·±£ÄãµÄLinuxϵͳÒѾװÖÃÁËJava Development Kit (JDK)ºÍAndroid SDK¡£
Ê×ÏÈ£¬ÄãÐèÒªÏÂÔز¢×°ÖÃJDK¡£Äã¿ÉÒÔ´ÓOracle¹Ù·½ÍøÕ¾ÉÏÏÂÔØ×îа汾µÄJDK×°ÖÃÆ÷£¬²¢Æ¾Ö¤ÌáÐѾÙÐÐ×°Öá£×°ÖÃÍê³Éºó£¬ÄãÐèÒªÉèÖÃJAVA_HOMEÇéÐαäÁ¿¡£ÔÚÖÕ¶ËÖÐÔËÐÐÒÔÏÂÏÂÁ
export JAVA_HOME=/path/to/your/jdk/directory export PATH=$JAVA_HOME/bin:$PATH
µÇ¼ºó¸´ÖÆ
½ÓÏÂÀ´£¬ÄãÐèÒªÏÂÔز¢×°ÖÃAndroid SDK¡£Äã¿ÉÒÔ´ÓAndroid¿ª·¢ÕßÍøÕ¾ÏÂÔØ×îа汾µÄAndroid SDK¡£½âѹËõÏÂÔصÄÎļþ£¬²¢½«½âѹºóµÄĿ¼Ìí¼Óµ½ÄãµÄϵͳ·¾¶ÖС£ÔÚÖÕ¶ËÖÐÔËÐÐÒÔÏÂÏÂÁ
export PATH=/path/to/your/android/sdk:$PATH
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÎÒÃÇ×îÏÈÉèÖÃVisual Studio Code¡£Ê×ÏÈ£¬·¿ªVisual Studio Code£¬È»ºóµã»÷×ó²àµÄÀ©Õ¹°´Å¥¡£ÔÚËÑË÷¿òÖÐÊäÈë”Android”£¬È»ºó×°ÖÔAndroid Extension Pack”À©Õ¹¡£
×°ÖÃÍê³Éºó£¬µã»÷×ó²àµÄÀ©Õ¹°´Å¥£¬È»ºóµã»÷ÓÒÉϽǵijÝÂÖͼ±ê£¬Ñ¡Ôñ”Settings”¡£ÔÚ”Extensions”ÉèÖÃÖУ¬µã»÷À©Õ¹ÃûΪ”Android”µÄÀ©Õ¹¡£ÔÚÓÒ²àµÄÉèÖÃÇøÓòÖУ¬ÎÒÃÇÐèÒª¾ÙÐÐÒÔÏÂÉèÖãº
“Sdk”: ÉèÖÃΪÄãµÄAndroid SDKĿ¼µÄ·¾¶¡£
ʾÀýÉèÖÃÈçÏ£º
{ "extensions.autoUpdate": true, "extensionPack.flashplayer.debugger": "~0.4.0", "extensions.ignoreRecommendations": false, "extensions.autoCheckUpdates": true, "android.sdk": "/path/to/your/android/sdk" }
µÇ¼ºó¸´ÖÆ
ÉèÖÃÍê³Éºó£¬ÄãÏÖÔÚ¿ÉÒÔʹÓÃVisual Studio Code¾ÙÐÐÒƶ¯Ó¦Óÿª·¢ÁË¡£½ÓÏÂÀ´£¬ÎÒ½«ÑÝʾÔõÑù½¨ÉèÒ»¸ö¼òÆÓµÄAndroidÓ¦Óá£
Ê×ÏÈ£¬µã»÷×ó²àµÄÀ©Õ¹°´Å¥£¬È»ºóµã»÷ÓÒÉϽǵļӺÅͼ±ê£¬Ñ¡Ôñ”New File”¡£ÔÚÐÂÎļþÖÐÊäÈëÒÔÏ´úÂ룺
import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textView = new TextView(this); textView.setText("Hello, World!"); setContentView(textView); } }
µÇ¼ºó¸´ÖÆ
ÉúÑÄÎļþΪ”MainActivity.java”¡£
½ÓÏÂÀ´£¬µã»÷×ó²àµÄÀ©Õ¹°´Å¥£¬È»ºóµã»÷ÓÒÉϽǵļӺÅͼ±ê£¬Ñ¡Ôñ”New Folder”¡£ÊäÈë”layout”×÷ΪÎļþ¼ÐµÄÃû³Æ¡£Ôٴεã»÷ÓÒÉϽǵļӺÅͼ±ê£¬Ñ¡Ôñ”New File”¡£ÔÚÐÂÎļþÖÐÊäÈëÒÔÏ´úÂ룺
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, World!" />
µÇ¼ºó¸´ÖÆ
ÉúÑÄÎļþΪ”activity_main.xml”¡£
ÏÖÔÚ£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öAndroidÏîÄ¿¡£µã»÷×ó²àµÄÀ©Õ¹°´Å¥£¬È»ºóµã»÷ÓÒÉϽǵļӺÅͼ±ê£¬Ñ¡Ôñ”New Folder”¡£ÊäÈë”app”×÷ΪÎļþ¼ÐµÄÃû³Æ¡£Ôٴεã»÷ÓÒÉϽǵļӺÅͼ±ê£¬Ñ¡Ôñ”New File”¡£ÔÚÐÂÎļþÖÐÊäÈëÒÔÏ´úÂ룺
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.helloworld"> <application> <activity android:name=".MainActivity" android:label="HelloWorld"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
µÇ¼ºó¸´ÖÆ
ÉúÑÄÎļþΪ”AndroidManifest.xml”¡£
ÏÖÔÚ£¬ÎÒÃÇÒѾÉèÖÃÍê³ÉÁËÒ»¸ö¼òÆÓµÄAndroidÓ¦Ó᣽ÓÏÂÀ´£¬ÎÒÃÇÐèÒª¹¹½¨ºÍÔËÐÐÓ¦Óᣵã»÷×ó²àµÄÀ©Õ¹°´Å¥£¬È»ºóµã»÷ÓÒÉϽǵÄÈý¸öµãͼ±ê£¬Ñ¡Ôñ”Run”¡£ÔÚµ¯³öµÄ²Ëµ¥ÖÐÑ¡Ôñ”Build and Run”¡£È·±£ÄãµÄAndroid×°±¸ÒѾÅþÁ¬µ½µçÄÔ£¬²¢´¦ÓÚ¿ª·¢ÕßģʽÖС£Visual Studio Code½«×Ô¶¯¹¹½¨²¢ÔËÐÐÄãµÄÓ¦Óá£
×ܽ᣺
ÔÚLinuxÉÏʹÓÃVisual Studio¾ÙÐÐÒƶ¯Ó¦Óÿª·¢ÊÇÒ»¸öºÜÊÇÇ¿Ê¢µÄÑ¡Ôñ¡£Í¨¹ý׼ȷÉèÖÃVisual Studio CodeºÍAndroid¿ª·¢ÇéÐΣ¬²¢¾ÙÐÐÊʵ±µÄÏîÄ¿ÉèÖã¬Äã¿ÉÒÔÔÚLinuxÉÏ¿ª·¢³ö¹¦Ð§Ç¿Ê¢µÄÒƶ¯Ó¦Óá£Ï£Íû±¾ÎĶÔÄãÔÚLinuxÉϾÙÐÐÒƶ¯Ó¦Óÿª·¢ÓÐËù×ÊÖú¡£
²Î¿¼Á´½Ó£º
Visual Studio Code¹Ù·½ÍøÕ¾£ºhttps://code.visualstudio.com/
Oracle¹Ù·½ÍøÕ¾£ºhttps://www.oracle.com/java/
Android¿ª·¢ÕßÍøÕ¾£ºhttps://developer.android.com/
ÒÔÉϾÍÊÇÔÚLinuxÉÏʹÓÃVisual Studio¾ÙÐÐÒƶ¯Ó¦Óÿª·¢µÄÍƼöÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡