java中的数组的长度是固定的.为什么Java允许大小为0的数组呢?
String[] strings = new String[0];
Run Code Online (Sandbox Code Playgroud) 我正在尝试在IntelliJ Idea中为我的libGDX项目添加Google Play服务.我已按照此处的设置指南进行操作:https://developers.google.com/android/guides/setup
这看起来非常简单.我刚刚在相应的部分中将这些行添加到我的build.gradle中,所以现在看起来像:
project(":android") {
apply plugin: "android"
apply plugin: 'com.android.application'
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
compile 'com.google.android.gms:play-services:11.2.0'
}
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试在Idea中同步我的gradle项目,以获得"无法解决"错误.
好吧,设置指南还说"确保每次更新Google Play服务时都更新此版本号",但问题是找到该版本号几乎是不可能的:根据Android SDK我的Google Play Services SDK版本manager是"43",到目前为止,我无法将这样的"11.2.0"或任何典型的版本字符串与"43"版本号相关联.并非设置指南对此没有任何说明.
无论如何,我从与此相关的众多问题中尝试了很多事情但无济于事.具体来说,我必须指出我确实更新了我的Android SDK,我确信它是Idea正在使用的那个(我已经三次检查了这个......):
我正在使用API级别26,但无论如何其他定义确实使用Android SDK的相同目录.此外,我没有在这台笔记本电脑上安装任何其他Android SDK,所以毫无疑问,Idea只使用那个和那个.
任何想法都非常受欢迎.
提前致谢!
我不知道如何描述这个问题.我搜索了很多,但我找不到任何解决方案.
此解决方案也没有帮助我-keepattributes EnclosingMethod:
dependencies {
compile project(':libraries:material-drawer')
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.commit451:PhotoView:1.2.4'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.viewpagerindicator:viewpagerindicator:2.4.3'
compile('com.github.afollestad.material-dialogs:commons:0.8.5.6@aar') {
transitive = true
}
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
}
Run Code Online (Sandbox Code Playgroud)
并且jar文件夹包含ormlite-android-4.48.jar和ormlite-core-4.48.jar.
Proguard文件:
-keepattributes EnclosingMethod
-dontobfuscate
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
-dontwarn android.support.v4.**
#FOR APPCOMPAT 23.1.1:
-keep class !android.support.v7.view.menu.*MenuBuilder*, android.support.v7.** { …Run Code Online (Sandbox Code Playgroud) 有没有办法知道某个应用程序是从Amazon App Store还是从Google Play商店下载的?当然,我的意思是在应用程序内部.
我已经为这两个站点部署了一个应用程序,而我更愿意知道客户在应用程序中的下载位置.我知道,我可以为每个服务部署不同的应用程序,但这增加了一些维护工作,如果有一些方法可以使用相同的包在应用程序中使用条件来解决它.
我正在使用最新的Facebook Android SDK,并在我最新发布的apk中从我的远程崩溃控制应用程序中的数十个用户那里获得该错误.我在这里看到了这样的错误,但大多数答案对于最后一个FB SDK来说太过时了,在这种情况下有两种奇怪的情况:
a)错误似乎是随机发生的.在我的所有设备上,我都无法重现它.
b)在该版本和前一版本之间FB逻辑没有任何变化,在之前的版本中我从未遇到过这样的错误.
由于我在这些版本之间的代码中找不到任何相关的差异,我认为问题是Android Tools在生成最后一个apk时可能发生的错误,但是给出的事实是我正在使用的那个apk和一直无法重现问题,尽管数十个或用户受到影响,数百个使用相同的apk都没有,我也放弃了这样的假设.
任何关于如何解决或只是调试这个东西的想法都是受欢迎的.
更多可能相关的信息:
该类实际上是在APK中导出的.我通过解压缩apk并使用dexdump查看classes.dex内部的内容来检查它.我无法想到其他的东西,因为它在我的所有设备中都能完美运行,如果班级不在那里,它就不会.
$〜/ android-sdks/build-tools/21.1.1/dexdump classes.dex | grep'com.facebook.internal.Utility $ 1'类描述符:'Lcom/facebook/internal/Utility $ 1;' #0 :(在Lcom/facebook/internal/Utility $ 1;)#1 :(在Lcom/facebook/internal/Utility $ 1;)#2 :(在Lcom/facebook/internal/Utility $ 1;)#0 :(在Lcom/facebook/internal/Utility $ 1;)#0 :(在Lcom/facebook/internal/Utility $ 1;)#1 :(在Lcom/facebook/internal/Utility $ 1;)#2 :(在Lcom/facebook/internal中)/Utility $ 1;)#3 :(在Lcom/facebook/internal/Utility $ 1;)
从loadAppSettingsAsync调用Utility的静态方法后,它似乎失败了,这恰好是同一个类中的静态方法.因此,如果com.facebook.internal.Utility类不存在或无法加载,那么首先如何执行com.facebook.internal.Utility.loadAppSettingsAsync?如果它存在并加载,为什么在com.facebook.internal.Utility上抛出NoClassDefFoundError?我很失落......
这里是来自splunk mint(以前称为bugsense)的堆栈,我刚刚更改了应用程序的名称.我用proguard地图文件回溯了它,但它似乎错过了一些行号:
java.lang.NoClassDefFoundError: com.facebook.internal.Utility$1
at com.facebook.internal.Utility.void loadAppSettingsAsync(android.content.Context,java.lang.String)(Unknown Source)
at com.facebook.Settings.void sdkInitialize(android.content.Context)(Unknown Source)
at com.facebook.UiLifecycleHelper.<init>(Unknown Source)
at net.iberdroid.androidgames.framework.impl.AndroidGame.void onCreate(android.os.Bundle)(Unknown Source)
at com.marzoa.ruletafree.xmas2012.RuletaAfortunadaGame.void onCreate(android.os.Bundle)(Unknown Source)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
at …Run Code Online (Sandbox Code Playgroud) 我在我的休闲游戏中添加了代码,通过社交网络,电子邮件等分享最高分.
对于l10n,这是我在strings.xml资源上定义的文本:
<string name="game_sharing_score" formatted="false">
My new High Score on Gamename: %d\n
You can download Gamename from here:\n
https://play.google.com/store/apps/details?id=gamepackage
</string>
Run Code Online (Sandbox Code Playgroud)
请注意,Gamename和gamepackage不是我正在使用的实际游戏包.
共享代码如下:
String shareScoreMsg = String.format(context.getString(R.string.game_sharing_score), highestScore);
Intent shareScoreInt = new Intent(Intent.ACTION_SEND);
shareScoreInt.setType("text/plain");
shareScoreInt.putExtra(Intent.EXTRA_TEXT, shareScoreMsg);
game.startActivity(Intent.createChooser(shareScoreInt, context.getString(R.string.game_sharing_score_title)));
Run Code Online (Sandbox Code Playgroud)
游戏是一个Activity,context是一个Application上下文,game_sharing_score_title是活动的标题"Share your score".无论如何,它自己的代码没有任何问题,它可以通过Google+,WhatsUp或Twitter进行分享,但是当用户选择通过FaceBook共享时,文本被剪切并且只发布最后一个链接,包含信息和FB从Google Play收集的一个图标图像,忽略链接之前的所有文本.
很明显,问题只在于Facebook,没有代码或字符串.
我想要找到的是某种解决方法,如果存在,以避免这些FB问题.说实话,我不喜欢Facebook,但它是一个拥有数百万人的社交网络,我不能简单地在游戏中忽略它.
非常感谢提前,
刚刚使用 CameraX 在 Android 中创建了一个相机预览,配置如下:
PreviewConfig previewConfig = new PreviewConfig.Builder()
.setLensFacing(CameraX.LensFacing.FRONT)
.setTargetResolution(new Size(720, 720))
.build();
Preview preview = new Preview(previewConfig);
Run Code Online (Sandbox Code Playgroud)
现在,问题是这样的目标分辨率可能不可用,在这种情况下,预览将选择与请求的分辨率接近的分辨率。我在这里问的是一种了解预览有效选择了哪种分辨率的方法。
提前致谢!
我刚刚开始学习Android开发.我使用Ubuntu 11.10和Eclipse.我已经安装了android开发所需的插件,我还编写了一些在模拟器上编译和运行的例子.
但有些多触控无法在模拟器上进行测试,所以我想在真正的三星Galaxy S2设备上进行测试.问题是我已经尝试了我在网上找到的所有内容,但仍然无法使用它.
当我运行./adb设备时,虽然设备已连接,但它确实没有显示.
$ lsusb
...
Bus 001 Device 012: ID 04e8:6860 Samsung Electronics Co., Ltd
$ ./adb devices
List of devices attached
Run Code Online (Sandbox Code Playgroud)
我已经按照网络上的说明以不同的方式修改了/etc/udev/rules.d/51-android.rules多次,但没有一个有所作为.目前我有这一行:
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", ATTRS{idProduct}="6860", MODE="0666", GROUP="plugdev"
Run Code Online (Sandbox Code Playgroud)
当然我尝试重新启动udev和adb服务,甚至重新启动整个系统,但它也没有用.
任何提示?
非常感谢提前,
我有一个字节数组,它是 128 位 AES 密钥,我想在 Python 脚本上使用该密钥,以使用上述密钥对一些信息进行加密。
我将密钥存储为十六进制字符串,例如“27821D90D240EA4F56D0E7612396C69E”(显然这不是真正的密钥,但具有相同的格式)。
我已经从该密钥生成了一个字节数组,这就是到目前为止我在其他语言(Java、C# 和 PHP)中使用 AES 密钥的方式,如下所示:
AES_KEY = bytearray.fromhex('27821D90D240EA4F56D0E7612396C69E')
Run Code Online (Sandbox Code Playgroud)
这工作正常,但是当我尝试使用它来创建密码时,它抱怨它需要第一个参数中的字符串:
cipher = AES.new(AES_KEY, AES.MODE_CBC, os.urandom(16));
Run Code Online (Sandbox Code Playgroud)
类型错误:参数 1 必须是字符串或只读缓冲区,而不是字节数组
我尝试从字节数组中获取字符串,如下所示:
AES_KEY = bytearray.fromhex('27821D90D240EA4F56D0E7612396C69E').decode()
Run Code Online (Sandbox Code Playgroud)
或者
AES_KEY = bytearray.fromhex('27821D90D240EA4F56D0E7612396C69E').decode('utf-8')
Run Code Online (Sandbox Code Playgroud)
无济于事,因为该键中有非 ASCII 和非 Unicode 值。
更换钥匙不是一个选择。
有任何想法吗?
预先非常感谢,
我正在尝试编写一些方法来将 Android 位图转换为 RGBA 字节数组,然后再转换回位图。问题是我似乎没有达到公式,因为颜色总是返回错误。我尝试过几种不同的假设,但没有成功。
所以,这是我认为很好的从 Bitmap 转换为 RGBA 的方法:
public static byte[] bitmapToRgba(Bitmap bitmap) {
int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];
byte[] bytes = new byte[pixels.length * 4];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
int i = 0;
for (int pixel : pixels) {
// Get components assuming is ARGB
int A = (pixel >> 24) & 0xff;
int R = (pixel >> 16) & 0xff;
int G = (pixel >> 8) & 0xff;
int B …Run Code Online (Sandbox Code Playgroud)