无法在Android Studio中解析符号 ‘Properties’。

huangapple go评论79阅读模式
英文:

Cannot Resolve Symbol 'Properties' on Android Studio

问题

以下是翻译好的内容:

在我的 Android Studio 中有两个错误。在 app 级别的 build.gradle 文件中,这行代码:

def localProperties = new Properties()

显示错误:无法解析符号 'Properties'。
还有在以下代码块中:

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

它显示错误:无法解析符号 'GradleException'。
我应该怎么做来解决这两个错误呢?

英文:

There are two errors in my Android Studio right now. In the app level build.gradle folder, the line

def localProperties = new Properties()

shows error Cannot Resolve Symbol 'Properties'
and on

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

it says Cannot Resolve Symbol GradleException,
What should I do to solve these two errors?

答案1

得分: 3

将项目的SDK设置为Android API平台版本29(或最新版本30),如下所示:

步骤1:

defaultConfig {
    ...
    minSdkVersion 16
    targetSdkVersion 30
}

步骤2:

GradleException()更新为FileNotFoundException()

步骤3:

请按照此链接进行操作:https://github.com/flutter/flutter/issues/29608#issuecomment-548649907

英文:

Set Project SDK to Android API Platform version 29 (or the latest version, 30), like so:

Step 1:

defaultConfig {
    ...
    minSdkVersion 16
    targetSdkVersion 30
}

Step 2:

update GradleException() to FileNotFoundException()

Step 3:

Please follow this: https://github.com/flutter/flutter/issues/29608#issuecomment-548649907

答案2

得分: 2

移除新的

def localProperties = Properties()
英文:

Remove new

def localProperties = Properties()

答案3

得分: 1

在我的情况下,与 Properties 或 SDK/Gradle 版本无关...等等。
只是因为在 build.gradle 中缺少了一些内容。错误消息只是结果,而不是原因。
仔细检查 build.gradle 中的每一行。

在我的情况下,花了大约一天的时间才发现 local.properties 中应该定义某些内容,但实际上并没有。所以 build.gradle 的同步失败了。然后,唯一的一行红色是 Properties....

英文:

In my case, it's nothing about the Properties, nor the SDK/Gradle versions... etc.
It's simply because something is missing in the build.gradle. The error message is just the result but not the cause.
Carefully examine every line in build.gradle.

In my case, it took about one day to find out that something should be defined in local.properties but wasn't there. So the sync for build.gradle failed. And then, the only one line in red is the Properties....

答案4

得分: 0

最近我也遇到了同样的问题,但我通过以下步骤解决了它:
1. 解决Symbol 'Properties'问题;

```groovy
def localProperties = new Properties()

从上述实例中移除/删除关键字 >> new <<,语法不需要/已弃用。

def localProperties = Properties()    # "像这样使用它"
  1. 解决Symbol GradleException问题;
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK未找到。在local.properties文件中定义flutter.sdk的位置。")
}

我使用的解决方案是导入该类;

import com.GradleException

将其复制并粘贴到文件的第一行;...app/build.gradle

希望这能有所帮助。


<details>
<summary>英文:</summary>

I had the same problem lately, but I resolved it with the following steps;
1. To resolve Symbol &#39;Properties&#39; issue;

`def localProperties = new Properties()`   

Remove/delete the keyword &gt;&gt; new &lt;&lt; from the above instance, the syntax is not needed/depercated.
     
`def localProperties = Properties()`    #&quot;use it like this&quot;

2. To resolve Symbol GradleException issue;

    `def flutterRoot = localProperties.getProperty(&#39;flutter.sdk&#39;)
    if (flutterRoot == null) {
    throw new GradleException(&quot;Flutter SDK not found. Define 
    location with flutter.sdk in the local.properties file.&quot;)
    }`

The solution I used was to import the class; 
    
    `import com.GradleException`    

Copy and paste it to the first line of the file; ...app/build.gradle

Hope this would help.
 

</details>



# 答案5
**得分**: 0

Symbol Properties解决方案正常运行。

对于GradleException,您需要在设置中设置Gradle的路径。
您需要进入“文件”中的“设置”以打开设置。在打开设置后,
点击“路径变量”,然后按以下方式添加Gradle的路径:

\AndroidStudioProjects\Project_directory\wrapper\dists\gradle-7.3.3-all\4295vidhdd9hd3gbjyw1xqxpo\gradle-7.3.3\bin


GradleException错误被解决了。
如果您使用的是Windows,在环境变量下设置类似的路径。

<details>
<summary>英文:</summary>

Symbol Properties solution worked fine.

For GradleException you need to set the path for Gradle in Settings.
You need to go to Settings From File Click Settings.  After Clicking Settings
Click Path Variable Add path to Gradle as follows:

\AndroidStudioProjects\Project_directory\wrapper\dists\gradle-7.3.3-all\4295vidhdd9hd3gbjyw1xqxpo\gradle-7.3.3\bin


GradleException error got solved for me.
If you are using Windows set the path similar under Environment Variable



</details>



huangapple
  • 本文由 发表于 2020年9月21日 01:46:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63981957.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定