AOSP-Android.mk里:=与+=的区别是啥?
AOSP-Android.mk里:=与+=的区别是啥?
:=
与+=
这两个常见于Android.mk文件中
比如说:
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-ex-camera2-portability
LOCAL_STATIC_JAVA_LIBRARIES += xmp_toolkit
LOCAL_STATIC_JAVA_LIBRARIES += glide
LOCAL_STATIC_JAVA_LIBRARIES += guava
LOCAL_STATIC_JAVA_LIBRARIES += jsr305
可以看到有:=
与+=
同样,我们也看到有
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
android-support-v7-recyclerview \
android-support-v7-palette \
android-support-dynamic-animation
我们还看到有
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 android-support-v7-recyclerview android-support-v7-palette
其实这三种写法作用是一样的。
前面我们看到
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-ex-camera2-portability
LOCAL_STATIC_JAVA_LIBRARIES += xmp_toolkit
LOCAL_STATIC_JAVA_LIBRARIES += glide
LOCAL_STATIC_JAVA_LIBRARIES += guava
LOCAL_STATIC_JAVA_LIBRARIES += jsr305
其实可以写成
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v13 \
android-ex-camera2-portability \
xmp_toolkit \
glide \
guava \
jsr305
以上这个是写成多行,换行连接用斜杠,这个做过linux开发的同学都知道的
也可以写成
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v13 android-ex-camera2-portability xmp_toolkit glide guava jsr305
以上这个就是写成了行了,空格分开
但是,如果这样写可以吗:
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES := android-ex-camera2-portability
LOCAL_STATIC_JAVA_LIBRARIES += xmp_toolkit
LOCAL_STATIC_JAVA_LIBRARIES += glide
LOCAL_STATIC_JAVA_LIBRARIES += guava
LOCAL_STATIC_JAVA_LIBRARIES += jsr305
如果这样写,android-support-v13
就没了
我们可以log输出一下给大家看。
实验部分
我们验证一下 :=与+=的区别
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#首次赋值
CUSTOM_PARAM := 10
#再次给值
CUSTOM_PARAM := 20
#猜猜这里输出啥?20,而不是10
#warning 输出是不是终止往下的,error会
$(warning $(CUSTOM_PARAM))
#再次设置值
CUSTOM_PARAM := 30
CUSTOM_PARAM += 40
#这里输出啥?3040
$(warning $(CUSTOM_PARAM))
CUSTOM_PARAM += 50
#这里输出啥?304050
$(warning $(CUSTOM_PARAM))
#这里是error,终止往下编译了
$(error "test...")