如何在Android Studio中构建sipdroid? [英] How to build sipdroid in Android Studio?

查看:104
本文介绍了如何在Android Studio中构建sipdroid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从此处下载了sipdroid项目,并尝试在Android Studio中导入.生成错误时:

I downloaded sipdroid project from here and tried to import in Android Studio. While building error:

错误:当前插件不推荐使用NDK集成.考虑尝试使用新的实验性插件.有关详细信息,请参见 http://tools.android.com/tech -docs/new-build-system/gradle-experimental .在gradle.properties中设置"android.useDeprecatedNdk = true"以继续使用当前的NDK集成.

Error: NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental. Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.`

我创建了名为gradle.properties的文件并添加了android.useDeprecatedNdk=true

I created file with name gradle.properties and added android.useDeprecatedNdk=true

然后在构建时,我在包含库时遇到了错误,例如:

Then while building I had errors with including libs, for example:

#include <myinttypes.h>
#include <spandsp/telephony.h>
#include <spandsp/g722.h>
#include <spandsp/private/g722.h>

#include <myinttypes.h>
#include <spandsp/telephony.h>
#include <spandsp/g722.h>
#include <spandsp/private/g722.h>

还有一个错误:

错误:任务':app:compileDebugNdk'的执行失败.
com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\ Users .... \ ndk-bundle \ ndk-build.cmd'以非零退出值2

Error:Execution failed for task ':app:compileDebugNdk'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users....\ndk-bundle\ndk-build.cmd'' finished with non-zero exit value 2

怎么了?如何在没有此错误的情况下构建项目?

What's wrong? How to build project without this errors?

推荐答案

首先,您始终可以使用命令行构建jni-part,方法是:

At first, you always can build jni-part with command line, doing this way:

$ export NDK_PROJECT_PATH=/opt/umake/AndroidStudioProjects/Sipdroid/app/src/main
$ /opt/umake/android/android-ndk/ndk-build

并使用以下命令创建gradle.properties文件:

and create gradle.properties file with

android.useDeprecatedNdk=true

位于项目的根部.

使用新的 build.gradle (模块:app)将是:

And with new build.gradle (Module: app) will be this:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 21
    buildToolsVersion "21.0.1"

    defaultConfig {
        applicationId "org.sipdroid.sipua"
        minSdkVersion 5
        targetSdkVersion 21

        ndk {
            moduleName "OSNetworkSystem"
        }
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    sourceSets.main.jni.srcDirs = [] // disable automatic ndk-build call, which ignore our Android.mk
    sourceSets.main.jniLibs.srcDir 'src/main/libs'
}

它对我有用.

通常,我使用实验性Android Gradle插件,它对于本机项目要好得多.将 sipdroid 导入Android Studio后,您需要将 build.gradle (模块:应用)更改为:

Usually I use Experimental Android Gradle Plugin, it much better for native projects. After import sipdroid to Android Studio you need to change build.gradle (Module: app) to this:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 21
        buildToolsVersion = "21.0.1"

        defaultConfig.with {
            applicationId = "org.sipdroid.sipua"
            minSdkVersion.apiLevel = 10
            targetSdkVersion.apiLevel = 21
        }
    }
    compileOptions.with {
        sourceCompatibility=JavaVersion.VERSION_1_7
        targetCompatibility=JavaVersion.VERSION_1_7
    }
    /*
     * native build settings
     */
    android.ndk {
        moduleName = "OSNetworkSystem"
        /*
         * Other ndk flags configurable here are
         * cppFlags.add("-fno-rtti")
         * cppFlags.add("-fno-exceptions")
         * ldLibs.addAll(["android", "log"])
         * stl       = "system"
         */
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file('proguard-rules.txt'))
        }
    }
    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
        create("arm7") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("arm8") {
            ndk.abiFilters.add("arm64-v8a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
        create("x86-64") {
            ndk.abiFilters.add("x86_64")
        }
        create("mips") {
            ndk.abiFilters.add("mips")
        }
        create("mips-64") {
            ndk.abiFilters.add("mips64")
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
}

并从以下位置更改build.gradle(整个项目,根目录)中的类路径:

and change classpath in build.gradle (whole project, root directory) from

 'com.android.tools.build:gradle:1.5.0'

'com.android.tools.build:gradle-experimental:0.4.0'

并在项目根目录中使用'android.useDeprecatedNdk = true'删除gradle.properties文件.

and delete gradle.properties file with 'android.useDeprecatedNdk=true' at the root of the project.

构建后,Android Studio将通过 Gradle Build Messages 消除包含源代码中的许多错误,并通过单击相应的消息来定位它们.

After build Android Studio will eliminate with Gradle Build Messages lots of errors in sources with includes, and locate them by clicking at corresponding message.

我看不到带有实验性Android Gradle插件的任何其他变体,而是更改了cpp和c文件中的包含内容,如下所示:

I don't see any other variants with Experimental Android Gradle Plugin, rather than to change includes in cpp and c-files like this:

例如 ndk/silk/src/SKP_Silk_main_FIX.h :

#include "SKP_Silk_typedef.h"

#include "../interface/SKP_Silk_typedef.h"

可悲的是,此片段与Gradle实验插件非常感谢,但没有效果.

It's sad that this fragment synch with Gradle Experimental Plugin gratefully, but hasn't effect.

android.sources {
    main {
        jni {
            source {
                srcDirs = []
            }
        }
    }
}

有来自的解决方案 如何在新的gradle构建系统中使用自定义Android.mk

android.sources{
    main.jni {
        source {
            srcDirs = []
        }
    }
    main.jniLibs {
        source {
            srcDirs = ['src/main/libs']
        }
    }
}

似乎插件 gradle-experimental:0.4.0 中的 bug 会引发此错误

It seems a bug in plugin gradle-experimental:0.4.0 throws this error

BError:Attempt to read a write only view of model of type 'java.lang.Object' given to rule 'model.android.sources'

但如果删除 jni 并仅保存 libs 目录,则 gradle-experimental:0.3.0-alpha7 可以正常工作.

but gradle-experimental:0.3.0-alpha7 works fine if remove jni and save only libs directory.

这篇关于如何在Android Studio中构建sipdroid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆