1. 程式人生 > >導包錯誤和ButterKnife的使用

導包錯誤和ButterKnife的使用

1.Android xxx is not translated in zh解決辦法

lintOptions {

    checkReleaseBuilds false

    // Or, if you prefer, you can continue to check for errors in release builds,

    // but continue the build even when errors are found:

    abortOnError false

}

 

 

Error:Execution failed for task ':app:javaPreCompileDebug'.

> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.

    - butterknife-6.0.0.jar (com.jakewharton:butterknife:6.0.0)

  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.

  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

 

android {

    ...

    defaultConfig {

        ...

        //新增如下配置就OK了

        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }

    }

    ...

}

 

2, 將Eclipse專案匯入到Android studio 中 很多點9圖出現問題解決方法:

在build.gradle裡新增以下兩句:

aaptOptions.cruncherEnabled = false     

aaptOptions.useNewCruncher = false

 

 

 

3,ButterKnife的使用

(1)activity裡使用

導包(as版本3.1以上)

defaultConfig {

   。。。。。。

    javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }

}

implementation 'com.jakewharton:butterknife:8.8.1'

implementation 'com.jakewharton:butterknife-compiler:8.8.1'//fragment裡使用必備的包

ButterKnife.bind(this);

(2)fragment裡使用

private Unbinder unbinder;

 

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

view = inflater.inflate(R.layout.four_activity, container, false);

unbinder = ButterKnife.bind(this, view);

init();

return view;

}

/**

* onDestroyView中進行解綁操作

*/

@Override

public void onDestroyView() {

super.onDestroyView();

unbinder.unbind();

}