1

I have received an old code, coded in 2014 and I was requested to update some functionalities.

I am having problems running the code, for it was built on Eclipse and now I imported it to Android Studio.

First of all, the code calls 3 libraries that are included in the project, one of them is in cpp. This is why I think it was needed to add the bundle-ndk.

I added: android.useDeprecatedNdk=true to gradle-wrapper.properties

These are the gradle files I currently have:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

First Library Gradle

apply plugin: 'com.android.library'


android {
    compileSdkVersion 16
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 5
        targetSdkVersion 16
    }

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

Second Library

apply plugin: 'com.android.library'

android {
    compileSdkVersion 16
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 5
        targetSdkVersion 5
    }

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

dependencies {
    compile project(':FirstLibrary')
    compile 'com.android.support:support-v4:18.0.0'
    compile files('libs/libGoogleAnalyticsV2.jar')
}

Third Library

apply plugin: 'com.android.library'

android {
    compileSdkVersion 16
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 5
        targetSdkVersion 7
    }

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

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

Module Gradle of Project

apply plugin: 'com.android.application'

android {
    compileSdkVersion 8
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.application.id"
        minSdkVersion 8
        targetSdkVersion 17
    }

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

dependencies {
    compile project(':secondLbrary')
    compile project(':thirdLibrary')
}

Latest Error Received:

Error:Execution failed for task ':library:compileDebugNdk'.

Error: Your project contains C++ files but it is not using a supported native build system. Consider using CMake or ndk-build integration with the stable Android Gradle plugin: https://developer.android.com/studio/projects/add-native-code.html or use the experimental plugin: http://tools.android.com/tech-docs/new-build-system/gradle-experimental.

What can I do to investigate this?

halfer
  • 19,824
  • 17
  • 99
  • 186
coder
  • 5,200
  • 3
  • 20
  • 45

2 Answers2

2

This is usually related to gradle version - you should update to recent version and try again. Look here Plugin is too old.

Also - why do you need "com.android.tools.build:gradle-experimental:0.7.0-alpha4"?

yakobom
  • 2,681
  • 1
  • 25
  • 33
  • Thank you for your assistance, initially when I built the project it was giving me the following error: Error: NDK integration is deprecated in the current plugin. After some research I understood that I need to use gradle experimental since as mentioned earlier one of the Libraries is in cpp. – coder Jul 05 '17 at 07:59
  • You should consider migrating to the stable version: http://tools.android.com/tech-docs/new-build-system/gradle-experimental/migrate-to-stable – yakobom Jul 05 '17 at 08:08
  • I have followed the suggested link, unfortunately I am still facing this Error: NDK integration is deprecated in the current plugin. Will update the question to include the changes made – coder Jul 06 '17 at 06:37
  • What Android Studio version are you using? – yakobom Jul 06 '17 at 06:57
  • 2.1.1, shall I update it? would the problem be solved? – coder Jul 06 '17 at 07:05
  • I think it is recommended... If you followed the link I gave in my comment above, you should have seen the first sentence: "Android Studio 2.2 and higher support building C/C++ components of your Android project with two new options: CMake and ndk-build". – yakobom Jul 06 '17 at 07:09
  • i moved to a new android version: I am getting this error now: Error:Execution failed for task ':library:compileDebugNdk'. > Error: Your project contains C++ files but it is not using a supported native build system. Consider using CMake or ndk-build integration with the stable Android Gradle plugin: https://developer.android.com/studio/projects/add-native-code.html or use the experimental plugin: http://tools.android.com/tech-docs/new-build-system/gradle-experimental. – coder Jul 06 '17 at 10:16
  • It seems like you are still not using the new build system. It is hard to figure out why - I would do a second pass against the instructions, you must have missed something. – yakobom Jul 08 '17 at 16:59
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/16659347) – ADreNaLiNe-DJ Jul 10 '17 at 11:05
  • @ADreNaLiNe-DJ Generally speaking, you are correct. But this was not really a link only answer. I have referred to the link after writing my recommendation - "update to recent version". In the link there are some suggestions and insights from users, and a lot of them. What's the point of putting all that mess here? As a user reading other people's answers, I would not want that in this case. – yakobom Jul 10 '17 at 11:14
  • @yakobom You can quote interesting parts of the link you provide to enhance your answer. That's the point. – ADreNaLiNe-DJ Jul 10 '17 at 11:16
  • How did you link you c++ project? Did you follow [the guide](https://developer.android.com/studio/projects/add-native-code.html)? – r0n9 Jul 12 '17 at 15:06
  • I did for one small testing project. Why, what are you facing? – yakobom Jul 13 '17 at 04:00
0

For compiling cpp code in Android Studio:

  1. you need to download CMAKE, LLDB and NDK on Android SDK Manager.

  2. you need to make CMakeList.txt and need to put script for compiling cpp files.

  3. you need to put following lines in build.gradle:

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    
halfer
  • 19,824
  • 17
  • 99
  • 186
Yuichi Akiyoshi
  • 409
  • 5
  • 19
  • I had also same problems and I solved with this answer. Thanks –  Jul 06 '17 at 13:34
  • Thank you for your contribution, I am using ndk-build, as I have been reading that you either use NDK or CMake. – coder Jul 07 '17 at 04:47
  • I downloaded LLDB and NDK and I am setting the location of the ndk-build in the local.properties and I have set android.useDeprecatedNdk=true in gradle-wrapper.properties. – coder Jul 07 '17 at 04:50