Android SDK 开发流程
1创建library
1、点击file –> new—->new Module
2、点击 next
3、编写SDK内容
public class LogUtils {private static String customTagPrefix = \"lib日志\";private static String generateTag() {StackTraceElement caller = new Throwable().getStackTrace()[2];String tag = \"%s.%s(L:%d)\";String callerName = caller.getClassName();callerClazzName = callerName.substring(callerClazzName.lastIndexOf(\".\") + 1);tag = String.format(Locale.ENGLISH,tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + \":\" + tag;return tag;}public static void e(String message) {Log.e(generateTag(), message);}}
2、项目内创建module依赖
implementation project(path: \':libraryname\')
3、生成aar文件
4、查看aar文件
5、引用aar文件
将 .aar 文件放入项目libs目录下
再 module的build.gradle文件中加入以下代码
repositories {flatDir {dirs \'libs\'}}dependencies {implementation fileTree(include: [\'*.jar\'], dir: \'libs\')implementation \'com.android.support:appcompat-v7:28.0.0\'implementation(name: \'libraryname-release\', ext: \'aar\')}
6、调用
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);LogUtils.e(\"日志测试\");}