Android Studio, Eclipse import Sina Micro-blog Android SDK Third-party login Demo

Source: Internet
Author: User
Tags wrapper zip
1. Download the Extract SDK
Download the Weibo Android SDK Pack first:
Open URL: https://github.com/sinaweibosdk/weibo_android_sdk
Download the SDK to the local, unpacked directory structure:
Click to enter the "DEMO-SRC" directory, the structure is as follows:
Import all two of the above items into eclipse!!
2. Lead Demo to eclipse
The file encoding for two items was modified separately to UTF-8, saved.
3. Modify Debug.keystore
MD5 tool is based on Keysto Re to generate the signature, the keystore generated by the same signature is not the same. This demo signature is to use the official website to mention
for the keystore generated, to run the demo program smoothly, need? Line set ring is to replace KeyStore, two methods to choose one operation:
Mode one: Replace KeyStore: Replace the Android default Debug.keystore (in C:\Users\XXXXX\.android directory) with the officer
side The debug.keystore provided on the GitHub.
Mode Two: Set up engineering KeyStore in eclipse: Click "Windowspreferencesandroidbuild" in Eclipse, in
Cu Stom Debug KeyStore Select the Debug.keystore in the Demo, the following figure, click Applyok,demo can run normally.
Note: This step is required, and if there is no replacement, the demo program will not be able to properly authorize success at run time. Before you replace it, it is a good idea to back up
the original debug.keystore. GitHub Debug.keysotre is the official Sina, in addition to compiling and running the official DEMO, not to direct
to use it, for security reasons, users should provide a copy of their application Keyso Tre  
4. Repair Dependency
If eclipse still displays an error after the encoding has been modified, check to see if the dependencies of the project are problematic:
When you select Weibosdkdemo, right-click--properties--android--add, and then add WEIBOSDK as a Weibosdkdemo dependent item, as shown in the following figure. (If the red question mark is not displayed, then the dependency is OK)
5. Import items into Android studio
The most critical step is how to import projects from Eclipse into Android studio:
Right-click the item, select "Export"--android--generate gradle build files--and select the project package to be exported everywhere.

Then import the resulting project package into Android Studio. will prompt the error, we need to the project root directory in the Build.gradle file (possibly your Android studio use of the Gradle version and Gradle version of the plugin is different from mine, it is recommended to change to their own version of the use):


dependencies {
Classpath ' com.android.tools.build:gradle:0.12+ '
}

Instead we use the new to Gradle plug-in version:

dependencies {
Classpath ' com.android.tools.build:gradle:1.3.0 '
}

Note: If possible, you may also need to change the/gradle/wrapper/gradle-wrapper.properties in the project root directory

6. Recompile run
After the change, click "Sync Now", recompile project, you will find that the project did not error, in the simulator test, everything is normal.
, the code is compiled and then run in the Android emulator. The following figure:
===================================
The problem is that everything is not going so well and should be compiled for Android studio using Gradle. and gradle compilation successful requirements to be strict, you will find Sina Weibo's SDK demo run after several kinds of errors:
Error A:
Error:the project is using a unsupported version of the Android Gradle plug-in (0.12.2). The recommended version is 1.5.0.
Fix plugin version and sync project

Workaround: Change the Gradle plug-in version of the Build.gradle in the DEMO-SRC directory to the version you use for Android Studio (I'm using 1.5.0):


Java
dependencies {
Classpath ' com.android.tools.build:gradle:1.5.0 '
}
123 Dependencies {classpath ' com.android.tools.build:gradle:1.5.0 '}

Change the Gradle version in Demo-src/gradle/wrapper/gradle-wrapper.properties to the version that Android Studio uses (I'm using the latest Gradle version, 2.8):
Java
Distributionurl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
1 Distributionurl=https\://services.gradle.org/distributions/gradle-2.8-all.zip

Then "Sync Now" won't report the mistake.

Error B:
This error is caused by the laziness of Sina Weibo SDK developers, and the cause of the error is in the picture, so I'm going to classify it as a mistake here.
The error is as follows:
Error:execution failed for task ': Weibosdkdemo:mergedebugresources '.
> Crunching cruncher ic_login_button_blue_normal.9.png failed, logs
In fact, looking at compilation errors, or to see the Gradle console errors and warnings, as follows:
AAPT err (façade for 1170324693): Error:9-patch image C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\ Weibosdkdemo\res\drawable\ic_login_button_blue_normal.9.png Malformed.
AAPT err (façade for 1170324693): Frame pixels must is either solid or transparent (not intermediate).
AAPT err (façade for 1170324693): Found in pixel #2 along top edge.
AAPT err (façade for 1170324693): Error:9-patch image C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\ Weibosdkdemo\res\drawable\ic_login_button_blue_focused.9.png Malformed.
AAPT err (façade for 1170324693): Frame pixels must is either solid or transparent (not intermediate).
AAPT err (façade for 1170324693): Found in pixel #2 along top edge.
AAPT err (façade for 576922613): libpng error:not a PNG file
AAPT err (façade for 735358242): C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\WeiboSDKDemo\build\ Intermediates\exploded-aar\demo-src\weibosdk\unspecified\res\drawable-mdpi-v4\ic_com_sina_weibo_sdk_login_with _text.png:libpng Warning:iCCP:Not Recognizing known SRGB profile that has been edited
AAPT err (façade for 576922613): C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\WeiboSDKDemo\build\ Intermediates\exploded-aar\demo-src\weibosdk\unspecified\res\drawable-hdpi-v4\ic_com_sina_weibo_sdk_logo.png: Libpng Warning:iCCP:Not Recognizing known SRGB profile that has been edited
AAPT err (façade for 735358242): C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\WeiboSDKDemo\build\ Intermediates\exploded-aar\demo-src\weibosdk\unspecified\res\drawable-ldpi-v4\ic_com_sina_weibo_sdk_logo.png: Libpng Warning:iCCP:Not Recognizing known SRGB profile that has been edited
AAPT err (façade for 576922613): Error:9-patch image C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\ Weibosdkdemo\res\drawable\ic_login_button_blue_pressed.9.png Malformed.
AAPT err (façade for 706899532): C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\WeiboSDKDemo\build\ Intermediates\exploded-aar\demo-src\weibosdk\unspecified\res\drawable-xhdpi-v4\ic_com_sina_weibo_sdk_logo.png: Libpng Warning:iCCP:Not Recognizing known SRGB profile that has been edited
AAPT err (façade for 576922613): No marked region found edge.
AAPT err (façade for 576922613): Found along top edge.
AAPT err (façade for 1615154168): C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\WeiboSDKDemo\build\ Intermediates\exploded-aar\demo-src\weibosdk\unspecified\res\drawable-ldpi-v4\ic_com_sina_weibo_sdk_login_with _text.png:libpng Warning:iCCP:Not Recognizing known SRGB profile that has been edited
AAPT err (façade for 1561367387): C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\WeiboSDKDemo\build\ Intermediates\exploded-aar\demo-src\weibosdk\unspecified\res\drawable-mdpi-v4\ic_com_sina_weibo_sdk_logo.png: Libpng Warning:iCCP:Not Recognizing known SRGB profile that has been edited
AAPT err (façade for 1561367387): C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\WeiboSDKDemo\build\ Intermediates\exploded-aar\demo-src\weibosdk\unspecified\res\drawable-hdpi-v4\ic_com_sina_weibo_sdk_login_with _text.png:libpng Warning:iCCP:Not Recognizing known SRGB profile that has been edited
There are two main errors (I ignore the warning message here because the warning does not cause the compilation to fail). The warning message is also because there are problems with PNG pictures, you can Google the reasons and solutions. ):
1.AAPT err (façade for 1170324693): Error:9-patch image C:\Users\AlexY\Desktop\weibo_android_sdk-master\demo-src\ Weibosdkdemo\res\drawable\ic_login_button_blue_normal.9.png Malformed.
AAPT err (façade for 1170324693): Frame pixels must is either solid or transparent (not intermediate).
AAPT err (façade for 1170324693): Found in pixel #2 along top edge.
Reason: The report this mistake, is because the picture in the Weibosdkdemo is in fact not the point 9 picture, only is changed the suffix name. As I said earlier, Gradle compilation requires a higher, so it will not fail to compile in eclipse because of this error, but Android Studio will cause failure.
WORKAROUND: Will so hint not to point 9 picture file, use Android Studio's Point 9 picture editor, fix it to point 9 pictures.
2.AAPT err (façade for 576922613): libpng error:not a PNG file
Reason: This error is because the picture in the Weibosdkdemo is not a PNG format picture, but a JPG image, but is the developer of Sina directly changed to ". png" suffix name, so, Android Studio compilation does not pass.
Workaround: Find a picture that is not in PNG format, and Windows does not seem to have the tool, even if you right-click on the file properties. So, with the help of Android Studio's picture editor, open all the. png files in turn with Android studio, and finally discover:/demo-src/weibosdkdemo/res/drawable/ic_share_ Music_thumb.png is not in PNG format, but JPG.

You can then convert it to a PNG picture.
Error C:
Unexpected top-level EXCEPTION:
Com.android.dex.DexException:Multiple dex Files Define landroid/support/v4/accessibilityservice/ Accessibilityserviceinfocompat$accessibilityserviceinfoversionimpl;
At Com.android.dx.merge.DexMerger.readSortableTypes (dexmerger.java:579)
At Com.android.dx.merge.DexMerger.getSortedTypes (dexmerger.java:535)
At Com.android.dx.merge.DexMerger.mergeClassDefs (dexmerger.java:517)
At Com.android.dx.merge.DexMerger.mergeDexes (dexmerger.java:164)
At Com.android.dx.merge.DexMerger.merge (dexmerger.java:188)
At Com.android.dx.command.dexer.Main.mergeLibraryDexBuffers (main.java:504)
At Com.android.dx.command.dexer.Main.runMonoDex (main.java:334)
At Com.android.dx.command.dexer.Main.run (main.java:277)
At Com.android.dx.command.dexer.Main.main (main.java:245)
At Com.android.dx.command.Main.main (main.java:106)
reason: because the Weibosdkdemo/build.gradle file has been added two times weibosdk dependencies, as follows:


dependencies {
Compile Filetree (dir: ' Libs ', include: ' *.jar ')
Compile project (': Weibosdk ')
Compile project (': Weibosdk ')
}


And Weibosdk/libs under the Support-v4.jar, so that prompted SUPPORT-V4 package multiple import, resulting in the compilation failed.
WORKAROUND: Delete the duplicate row, which is called the following:

dependencies {
Compile Filetree (dir: ' Libs ', include: ' *.jar ')
Compile project (': Weibosdk ')

}


Then "Sync Now" and recompile, it will not report this error.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.