使用importet .jar文件构建应用程序时出错

时间:2016-12-22 11:27:23

标签: android gradle jar

在我的项目中,我导入了在Eclipse中编码和导出的jar文件。当我尝试运行app时出现错误:

enter image description here

这是我的gradle文件:

enter image description here

我尝试添加targetCompatibility和sourceCompatibility,但没有任何效果。

4 个答案:

答案 0 :(得分:2)

使用Java 1.8并在build.gradle文件中设置以下内容

android {
     compileSdkVersion 23
     buildToolsVersion 24rc3

     defaultConfig {
    ...        
         jackOptions {
            enabled true
        }
    }
   dexOptions {
    incremental true
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

答案 1 :(得分:1)

您应该下载并使用Java 8.它说This is caused by library dependencies that have been compiled using Java 8 or above.

您应该始终阅读从编译器

收到的错误

答案 2 :(得分:1)

一段时间后,我按如下方式配置build.gradle,它开始工作。

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"
    defaultConfig {
    ...
       jackOptions {
           enabled true
       }
       multiDexEnabled true
    }
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

答案 3 :(得分:0)

尝试

import {HostListener, Directive } from "@angular/core";

@Directive({
    selector: 'textarea[autoGrow]',
})

export class AutoGrowDirective {
    @HostListener('input', ['$event.target'])
    onInput(inputElement: HTMLTextAreaElement): void {
        this.growHeight(inputElement);
    }


@HostListener('focusout', ['$event.target'])
onFocusout(inputElement: HTMLTextAreaElement): void {
    this.shrinkHeight(inputElement);
}
@HostListener('focus', ['$event.target'])
onFocus(inputElement: HTMLTextAreaElement): void {
    this.showFull(inputElement);
}
private initialHeight: number = 0;
public growHeight(textArea:HTMLTextAreaElement): void {
    textArea.style.overflow = "hidden";
    this.setInitialHeight(textArea.offsetHeight);
    if(textArea.value.trim() == ""){
        textArea.style.height = "100px";
    } else if(textArea.scrollHeight > textArea.offsetHeight){
        textArea.style.height = (textArea.scrollHeight+10) + "px";
    }
}
public shrinkHeight(textArea:HTMLTextAreaElement): void {
    if(textArea.scrollHeight > this.initialHeight){
        let button: HTMLElement = document.createElement('button'); //, {id: 'textareaHeightChange', class: 'btn', type:""}
        button.id = 'textareaHeightChange';
        button.className = 'btn';
        button.textContent = 'Show More';
        // button.onclick = this.showFull2(); // on click invoke a function
        console.info(button);
        textArea.insertAdjacentElement('afterend',button); // insert this button only once
        // <button id="textareaHeightChange" class="btn" type="">Show More</button>

    }
    textArea.style.height = this.initialHeight + "px";
    textArea.style.overflow = "hidden";
}

public showFull(textArea:HTMLTextAreaElement): void {
    textArea.style.height = textArea.scrollHeight + "px";
}

private setInitialHeight(height:number):void {
    if(this.initialHeight == 0)
        this.initialHeight = height;
}
private getInitialHeight(): number{
    if(this.initialHeight != 0)
        return this.initialHeight;
}

这对我有用。