-
首先使用Android Studio新建一个安卓项目
-
修改build.gradle文件
2.1 修改项目的build.gradle(项目根目录下的)
将build.gradle中buildscript下的内容修改为如下图所示:
然后新增subprojects内容,如下图所示:
因此最终我的项目build.gradle内容如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: "https://github.com/rosjava/android_core/raw/kinetic/buildscript.gradle"
}
subprojects {
apply plugin: 'ros-android'
afterEvaluate { project ->
android {
// Exclude a few files that are duplicated across our dependencies and
// prevent packaging Android applications.
packagingOptions {
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE.txt"
}
}
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.2 在module下面的build.gradle中添加依赖:
如下图所示的:compile 'org.ros.android_core:android_10:[0.3,0.4)'
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.xuyang.hopeapplication"
minSdkVersion 15
targetSdkVersion 26
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 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'org.ros.android_core:android_10:[0.3,0.4)'
}
上面代码中的appcompat要对应你项目中:File>Settings>Appearance & Behavior>Systerm Settings>Updates中的Android SDK TOOL的大版本,如下图中的 26.1.1 ,小版本要对应你Tools>SDK Manager>SDK Tools(勾选Show Package Details)中相同大版本且已经安装的小版本号(都没有就自己勾选一个安装),如下图,
constraint-layout的版本也是一样的道理,也是在 SDK Tools中,勾选Show Package Details后,拉滑动条到最下面,即可看到已经安装了的版本,在build.gradle中修改为已经安装了的版本即可。
2.3 修改module下src>main>AndroidManifest.xml
在上面提到的文件中新增
xmlns:tools="http://schemas.android.com/tools"
tools:replace="android:icon"
修改后的文件内容如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xuyang.hopeapplication">
<application xmlns:tools="http://schemas.android.com/tools"
tools:replace="android:icon"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
然后基本上就完成了,重新Sync Project就可以了。
如果有错误,希望能够留言指正。