Android 导入Rosjava/Android_core示例

  1. 首先使用Android Studio新建一个安卓项目

  2. 修改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就可以了。

    如果有错误,希望能够留言指正。

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值