dlib-android-app icon indicating copy to clipboard operation
dlib-android-app copied to clipboard

org.gradle.tooling.BuildException: invalid code lengths set

Open karticchaudhary opened this issue 5 years ago • 10 comments

I am getting this error when i am trying to build project.

karticchaudhary avatar Dec 03 '18 09:12 karticchaudhary

I am having same issue, does anyone find any solution?

awaistoor avatar Dec 05 '18 12:12 awaistoor

  • What went wrong: Execution failed for task ':demo:packageDebug'.

invalid code lengths set

karticchaudhary avatar Dec 11 '18 07:12 karticchaudhary

me too having same issue, any luck in finding solution for this, anyone?

ajayram1509 avatar Jan 15 '19 04:01 ajayram1509

I am having same issue :/ help me please ..
error : invalid code lengths set shape_predictor_68_face_landmarks.dat > no problem when I delete it but I should use

sdatakn avatar Jan 19 '19 23:01 sdatakn

The only solution I came up with is by downgrading your project level gradle to 3.1.0. It seems to be working on it. The only reason why I think it is causing the problem is latest gradle plugin try to validate every file in your project and somehow it cant read the shape_predictor_68_face_landmarks.dat. I really hope we find the proper answer to this issue though.

awaistoor avatar Jan 19 '19 23:01 awaistoor

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

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
    classpath "com.github.dcendents:android-maven-gradle-plugin:1.4.1"
    

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects { repositories { google() jcenter() } }

task clean(type: Delete) { delete rootProject.buildDir } ext { groupName = 'com.tzutalin.dlib' artifactName = 'dlib' artifactDescription = 'An Android library to wrap dlib library to use face and landmark detection' artifactLabels = ['dlib', 'android'] releaseVersionCode = 1 releaseVersionName = '1.0.4'

androidBuildToolsVersion = '28.0.3'
androidSupportSdkVersion = '28.0.0'

}

app gradle: apply plugin: 'com.android.application'

android { compileSdkVersion 28 defaultConfig { applicationId "org.hra.fastface" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { arguments = [ "androidManifestFile": "$projectDir/src/main/AndroidManifest.xml".toString() ] } } }

// splits{ // abi { // enable true // reset() // include 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'x86', 'x86_64' // universalApk false // } // } // buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main { assets.srcDirs = ['src/main/res/raw'] } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }

buildscript { repositories { mavenCentral() mavenLocal() }

}

repositories { mavenCentral() } def AAVersion = '4.5.0'

dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.github.dexafree:materiallist:3.0.1' implementation 'com.jakewharton.timber:timber:4.5.1' implementation project(':dlib') annotationProcessor "org.androidannotations:androidannotations:$AAVersion" implementation "org.androidannotations:androidannotations-api:$AAVersion" androidTestImplementation "com.android.support:support-annotations:${rootProject.ext.androidSupportSdkVersion}" testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:0.5' }

//dlib gradle apply plugin: 'com.android.library'

// required by POM version = "${rootProject.ext.releaseVersionName}" group = "org.hra.fastface"

android { compileSdkVersion 28 buildToolsVersion '28.0.3'

defaultConfig {
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "${rootProject.ext.releaseVersionName}"

    ndk{
        abiFilters 'armeabi-v7a'
    }
}

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

android {
    lintOptions {
        abortOnError false
    }
}

// Use prebilt *.so. Don't run ndk-build
sourceSets {
    main {
        jniLibs.srcDirs = ["src/main/jniLibs"]
    }
}

}

configurations { javadocDeps }

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "com.android.support:appcompat-v7:28.0.0" javadocDeps "com.android.support:appcompat-v7:28.0.0" implementation "com.android.support:support-annotations:${rootProject.ext.androidSupportSdkVersion}" javadocDeps "com.android.support:support-annotations:${rootProject.ext.androidSupportSdkVersion}" }

buildscript { repositories { mavenCentral() }

}

// call regular ndk-build(.cmd) script from app directory def GetNDKDir() { def localProperties = new Properties()

def NDK_SEARCH_VARS = ['ANDROID_NDK_HOME', 'ANDROID_NDK_ROOT', 'NDKROOT', 'NDKHOME']
def ndk_path = null

def lim = (Os.isFamily(Os.FAMILY_WINDOWS)) ? '\\' : '/'

// Search Local.Properties file
try {
    localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkDir = localProperties.getProperty('ndk.dir')
    ndk_path = ndkDir != null ? ndkDir + lim : null;
} catch (java.io.FileNotFoundException e) {
    println 'local.properties file not found'
}

// Search env var
if (ndk_path == null){
    for (String var : NDK_SEARCH_VARS) {
        def v = System.getenv(var)

        if (v != null) {
            ndk_path = v + lim
            println "found in System Environment *$var = " + ndk_path
            break
        }
    }
} else {
    println 'found in local.properties *NDK_PATH = ' + ndk_path
}

if (ndk_path == null) {
    println 'No NDK_PATH found'
    ndk_path = ''
}
return ndk_path

}

def NDKCommand() { if (Os.isFamily(Os.FAMILY_WINDOWS)) { return GetNDKDir() + "ndk-build.cmd" } else { return GetNDKDir() + "ndk-build" } }

apply plugin: 'com.jfrog.bintray' apply plugin: 'com.github.dcendents.android-maven'

def siteUrl = 'https://github.com/tzutalin/dlib-android-app' // Homepage URL of the library def gitUrl = 'https://github.com/tzutalin/dlib-android-app.git' // Git repository URL

install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' name 'An Android library to wrap dlib library' url siteUrl // Set your license licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id 'ajay' name 'ajay' email '[email protected]' } } scm { connection gitUrl developerConnection gitUrl url siteUrl

            }
        }
    }
}

}

task generateSourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier 'sources' }

task generateJavadocs(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath() .join(File.pathSeparator)) classpath += configurations.javadocDeps }

task generateJavadocsJar(type: Jar) { from generateJavadocs.destinationDir classifier 'javadoc' } generateJavadocsJar.dependsOn generateJavadocs

artifacts { archives generateJavadocsJar archives generateSourcesJar }

Properties properties = new Properties() if(project.rootProject.file('local.properties').isFile()) { properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = "maven"
        name = "dlib"
        version {
            name = "${rootProject.ext.releaseVersionName}"
            desc = 'An Android library to wrap dlib library'
            released  = new Date()
            vcsTag = "${rootProject.ext.releaseVersionName}"
        }

        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
    configurations = ['archives']
}

}

i've gone through so many references and tried by changing each and every line, i dont know what i did but magically it's started working.

ajayram1509 avatar Jan 20 '19 05:01 ajayram1509

:)

ajayram1509 avatar Jan 20 '19 05:01 ajayram1509

The solution is to explicitly declare your resource directory to the raw folder.

Add the following snippet to your Module:app build.gradle file -

android{ sourceSets { main{ assets.srcDirs = ['src/main/res/raw'] } } }

Tested and working.

dhruv2601 avatar Feb 09 '19 23:02 dhruv2601

The solution is to explicitly declare your resource directory to the raw folder.

Add the following snippet to your Module:app build.gradle file -

android{ sourceSets { main{ assets.srcDirs = ['src/main/res/raw'] } } }

Tested and working.

You're legend bro

ajayram1509 avatar Feb 10 '19 13:02 ajayram1509

    classpath "com.android.tools.build:gradle:4.1.2"

use the latest gradle

DevBash18 avatar Mar 21 '21 13:03 DevBash18