0

I am trying to integrate Tensorflow with Android Studio. I created the module and all library dependencies but i keep getting this error:

Build file '/home/User/AndroidStudioProjects/MyApp/tensorflow-android-1.13.1/build.gradle' line: 4 A problem occurred evaluating project ':tensorflow-android-1.13.1'.

Could not find method implementation() for arguments [DefaultProjectDependency{dependencyProject='project ':app'', configuration='default'}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Meanwhile if i try using compile instead of implementation(), it's already deprecated. My build.gradle file of the project is:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
        maven { url "https://chaquo.com/maven" }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        implementation'org.tensorflow:tensorflow-android:+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "com.chaquo.python:gradle:7.0.2"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
       // maven{
       //     url 'https://maven.google.com/'
       //     name 'Google'
       // }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

medinaz
  • 23
  • 2
  • 12

1 Answers1

1

Generally, that's indicative of the java or java-library plugin missing, or the kotlin equivalent. Do you have anything like that appearing in your gradle file?

If not, try adding the following block above your dependencies, selecting either the java or the kotlin line, depending on your development language.

plugins {
    id 'java'
    kotlin("jvm") version "1.3.70"
}

Furthermore, given the latest information you've provided, the issue, I believe, comes from this line:

implementation'org.tensorflow:tensorflow-android:+'

As far as I am aware, buildscript dependencies are only useful for gradle plugins, not code dependencies. Furthermore, inside the dependencies block under buildscript, you can only add the plugins to the classpath, which you'll then apply using apply.

However, getting back to the issue at hand, try the following changes to the file:


buildscript {

    repositories {
        google()
        jcenter()
        maven { url "https://chaquo.com/maven" }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "com.chaquo.python:gradle:7.0.2"
    }
}

plugins {
    id 'java'
    kotlin("jvm") version "1.3.70"
}
allprojects {
    apply plugin: 'java'
    apply plugin: 'kotlin'

    repositories {
        google()
        jcenter()
       // maven{
       //     url 'https://maven.google.com/'
       //     name 'Google'
       // }
    }
    dependencies {
        implementation'org.tensorflow:tensorflow-android:+'
    }

task clean(type: Delete) {
    delete rootProject.buildDir
}

Let me know if it helps. You might have to chose between `java` and `kotlin` based on your needs.
afterburner
  • 2,552
  • 13
  • 21
  • Would you mind posting a more complete example of your gradle file, please? – afterburner Mar 27 '20 at 15:50
  • @medinaz I've updated my answer, can you let me know if it works? – afterburner Apr 03 '20 at 13:44
  • 2
    Hello! Each android project has 2 gradle file one for the project and one for the app, the tensorflow dependency should be inserted in the build.gradle(:app) (NOT build.gradle(:ProjectName) ) file inside the dependencies tags. Thanks for the answer, it was helpful, now i don't have a problem on compiling the project. – medinaz Apr 03 '20 at 14:20