Note:
自从群主添加图片过后,导入Android Studio一直存在图片问题。
感谢 @改变 帮助:kissing_heart:,
只需要将 Project的gradle版本改为1.3.0就可以了。
示例如下:
build.gradle(Project:your-project’s-name)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
allprojects { repositories { jcenter() } }
task clean(type: Delete) { delete rootProject.buildDir }
|
【导入Android Studio】
- 1 新建Project
- 2 安装依赖API17
- 3 导入Eclipse Project
- 4 修改build.gradle (Module: androidTvWidget)
- 5 修改AndroidManifest.xml
- 6 切换工程
- 7 添加app的工程依赖
- 8 修改 activity_main.xml 和 MainActivity
- 9 运行app
1 新建Project
菜单 File—>New—>New Project
Android 最小版本SDK选着API15
2 安装依赖API17
已安装可忽略这步
由于该Eclipse工程compileSdkVersion为17,只需要API17的SDK Platform, Sources for Android SDK
3 导入Eclipse Project
菜单 File—>New—>New Module…—>Import Eclipse ADT Project—>next—>选择Eclipse工程目录—>next—>next—>Finish
修改build.gradle (Module: androidTvWidget)成如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| apply plugin: 'com.android.library'
android { compileSdkVersion 17 buildToolsVersion "19.1.0"
defaultConfig { // applicationId "com.open.androidtvwidget" minSdkVersion 15 targetSdkVersion 20 }
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } }
dependencies { compile 'com.android.support:support-v4:+' }
|
5 修改AndroidManifest.xml
修改androidTvWidget的AndroidManifest.xml成如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.open.androidtvwidget" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="20" />
<application android:allowBackup="true" android:label="@string/app_name" android:theme="@style/AppTheme" > </application>
</manifest>
|
6 切换工程
切换工程 为app
7 添加app的工程依赖
右键app—>Open Module Settings—>Modules(选择app)—>Dependencies—>加号图标(添加)—>3 Module Dependency—>选择:androidTvWidget—>OK
8 修改 activity_main.xml 和 MainActivity
MainActivity
1 2 3 4 5 6 7 8 9 10 11
| MainUpView mMainUpView;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mMainUpView = (MainUpView) findViewById(R.id.mainUpView); Drawable testDrawable = null; mMainUpView.setUpRectDrawable(testDrawable); // 设置边框图片 mMainUpView.setUpRectResource(R.drawable.white_light_10); // 设置边框图片. }
|
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >
<!-- 最顶层的边框移动 --> <com.open.androidtvwidget.view.MainUpView android:id="@+id/mainUpView" android:layout_width="wrap_content" android:layout_height="wrap_content" > </com.open.androidtvwidget.view.MainUpView>
</LinearLayout>
|
9 运行app
确认切换到app,如果能成功运行择证明导入库正确
Reference
How to import android project as library and NOT compile it as apk (Android studio 1.0)